This repository has been archived by the owner on Oct 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bb637ba
Showing
15 changed files
with
499 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea/ | ||
.gradle/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Copyright (C) 2017 - gmetal <gmetaxas@gmail.com> | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
jsoniter (json-iterator) Converter | ||
================= | ||
|
||
A `Converter` which uses [jsoniter][1] for serialization to and from JSON. | ||
|
||
The default jsoniter decoding mode is DecodingMode.REFLECTION_MODE. You can however | ||
use another DecodingMode, as provided by the jsoniter library. | ||
|
||
You can use [jitpack][2] to use the library. | ||
|
||
``` | ||
compile 'com.github.gmetal:converter-jsoniter:latest.version' | ||
``` | ||
|
||
[1]: http://jsoniter.com/ | ||
[2]: https://jitpack.io/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
group 'com.github.gmetal' | ||
version '0.1-SNAPSHOT' | ||
|
||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
maven { url "https://plugins.gradle.org/m2/" } | ||
} | ||
|
||
dependencies{ | ||
classpath 'gradle.plugin.nl.javadude.gradle.plugins:license-gradle-plugin:0.14.0' | ||
} | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
jcenter() | ||
} | ||
} | ||
|
||
apply plugin: 'com.github.hierynomus.license' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apply plugin: 'java-library' | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
|
||
compile 'com.squareup.retrofit2:retrofit:2.3.0' | ||
compile 'com.jsoniter:jsoniter:0.9.18' | ||
// https://mvnrepository.com/artifact/org.javassist/javassist | ||
compile group: 'org.javassist', name: 'javassist', version: '3.22.0-GA' | ||
} | ||
|
||
sourceCompatibility = "1.8" | ||
targetCompatibility = "1.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module external.linked.project.id=":converter-jsoniter" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$USER_HOME$/development/Android/Projects/Phabdroid" external.system.id="GRADLE" type="JAVA_MODULE" version="4"> | ||
<component name="FacetManager"> | ||
<facet type="android-gradle" name="Android-Gradle"> | ||
<configuration> | ||
<option name="GRADLE_PROJECT_PATH" value=":converter-jsoniter" /> | ||
</configuration> | ||
</facet> | ||
<facet type="java-gradle" name="Java-Gradle"> | ||
<configuration> | ||
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" /> | ||
<option name="BUILDABLE" value="true" /> | ||
</configuration> | ||
</facet> | ||
</component> | ||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7"> | ||
<output url="file://$MODULE_DIR$/build/classes/java/main" /> | ||
<output-test url="file://$MODULE_DIR$/build/classes/java/test" /> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" /> | ||
<excludeFolder url="file://$MODULE_DIR$/.gradle" /> | ||
<excludeFolder url="file://$MODULE_DIR$/build" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" exported="" scope="PROVIDED" name="retrofit-2.3.0" level="project" /> | ||
<orderEntry type="library" exported="" scope="PROVIDED" name="jsoniter-0.9.18" level="project" /> | ||
<orderEntry type="library" exported="" scope="PROVIDED" name="javassist-3.22.0-GA" level="project" /> | ||
<orderEntry type="library" exported="" scope="PROVIDED" name="okhttp-3.8.0" level="project" /> | ||
<orderEntry type="library" exported="" scope="PROVIDED" name="okio-1.13.0" level="project" /> | ||
</component> | ||
</module> |
59 changes: 59 additions & 0 deletions
59
converter-jsoniter/src/main/java/gr/gmetal/jsoniter/JsoniterConverterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Copyright (C) 2017 - gmetal <gmetaxas@gmail.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package gr.gmetal.jsoniter; | ||
|
||
import com.jsoniter.JsonIterator; | ||
import com.jsoniter.spi.DecodingMode; | ||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Type; | ||
import okhttp3.RequestBody; | ||
import okhttp3.ResponseBody; | ||
import retrofit2.Converter; | ||
import retrofit2.Retrofit; | ||
|
||
public class JsoniterConverterFactory extends Converter.Factory { | ||
|
||
public static JsoniterConverterFactory create() { | ||
|
||
return new JsoniterConverterFactory(DecodingMode.REFLECTION_MODE); | ||
} | ||
|
||
public static JsoniterConverterFactory create(final DecodingMode decodingMode) { | ||
|
||
return new JsoniterConverterFactory(decodingMode); | ||
} | ||
|
||
private JsoniterConverterFactory(final DecodingMode decodingMode) { | ||
|
||
JsonIterator.setMode(decodingMode); | ||
} | ||
|
||
@Override | ||
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, | ||
Retrofit retrofit) { | ||
|
||
return new JsoniterResponseBodyConverter<>((Class<?>) type); | ||
} | ||
|
||
@Override | ||
public Converter<?, RequestBody> requestBodyConverter(Type type, | ||
Annotation[] parameterAnnotations, | ||
Annotation[] methodAnnotations, | ||
Retrofit retrofit) { | ||
|
||
return new JsoniterRequestBodyConverter<>(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
converter-jsoniter/src/main/java/gr/gmetal/jsoniter/JsoniterRequestBodyConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright (C) 2017 - gmetal <gmetaxas@gmail.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package gr.gmetal.jsoniter; | ||
|
||
import com.jsoniter.output.JsonStream; | ||
import java.io.IOException; | ||
import okhttp3.MediaType; | ||
import okhttp3.RequestBody; | ||
import retrofit2.Converter; | ||
|
||
class JsoniterRequestBodyConverter<T> implements Converter<T, RequestBody> { | ||
|
||
private static final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8"); | ||
|
||
@Override | ||
public RequestBody convert(final T value) throws IOException { | ||
|
||
return RequestBody.create(MEDIA_TYPE, JsonStream.serialize(value)); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
converter-jsoniter/src/main/java/gr/gmetal/jsoniter/JsoniterResponseBodyConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright (C) 2017 - gmetal <gmetaxas@gmail.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package gr.gmetal.jsoniter; | ||
|
||
import com.jsoniter.JsonIterator; | ||
import java.io.IOException; | ||
import okhttp3.ResponseBody; | ||
import retrofit2.Converter; | ||
|
||
class JsoniterResponseBodyConverter<T> implements Converter<ResponseBody, T> { | ||
|
||
public static final int BUF_SIZE = 512; | ||
|
||
private Class<T> mCls; | ||
|
||
public JsoniterResponseBodyConverter(Class<T> cls) { | ||
|
||
mCls = cls; | ||
} | ||
|
||
@Override | ||
public T convert(final ResponseBody value) throws IOException { | ||
|
||
final JsonIterator parsedValue = JsonIterator.parse(value.byteStream(), BUF_SIZE); | ||
|
||
return parsedValue.read(mCls); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#Mon Dec 18 19:25:31 EET 2017 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip |
Oops, something went wrong.