Skip to content
This repository has been archived by the owner on Jun 16, 2019. It is now read-only.

Commit

Permalink
Recursive serialize/deserialize, resolves #15
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidan Follestad authored and Aidan Follestad committed Aug 24, 2017
1 parent 7c994b0 commit 001d791
Show file tree
Hide file tree
Showing 22 changed files with 332 additions and 237 deletions.
9 changes: 0 additions & 9 deletions .idea/codeStyleSettings.xml

This file was deleted.

2 changes: 0 additions & 2 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions .idea/copyright/profiles_settings.xml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

7 changes: 0 additions & 7 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

45 changes: 17 additions & 28 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 0 additions & 27 deletions .idea/modules/ason.iml

This file was deleted.

15 changes: 15 additions & 0 deletions .idea/modules/ason_main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/modules/ason_test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

3 changes: 1 addition & 2 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions ason.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="ason" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="com.afollestad" external.system.module.version="1.4.14" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.afollestad'
version '1.4.13'
version '1.4.14'

apply plugin: 'java'
apply plugin: 'idea'
Expand All @@ -15,7 +15,7 @@ buildscript {
}
dependencies {
classpath 'com.novoda:bintray-release:+'
classpath "com.diffplug.spotless:spotless-plugin-gradle:3.4.0"
classpath "com.diffplug.spotless:spotless-plugin-gradle:3.4.1"
}
}

Expand All @@ -35,7 +35,7 @@ publish {
userOrg = 'drummer-aidan'
groupId = 'com.afollestad'
artifactId = 'ason'
publishVersion = '1.4.13'
publishVersion = '1.4.14'
website = 'https://github.com/afollestad/ason'
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip
65 changes: 52 additions & 13 deletions src/main/java/com/afollestad/ason/Ason.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import org.json.JSONException;
import org.json.JSONObject;

/** @author Aidan Follestad (afollestad) */
/**
* @author Aidan Follestad (afollestad)
*/
@SuppressWarnings({"WeakerAccess", "unused", "unchecked", "SameParameterValue"})
public class Ason {

Expand Down Expand Up @@ -58,49 +60,83 @@ public Ason(@Nullable String json) {
}

public static Ason serialize(@Nullable Object object) {
return AsonSerializer.get().serialize(object);
return serialize(object, false);
}

public static Ason serialize(@Nullable Object object, boolean recursive) {
return AsonSerializer.get().serialize(object, recursive);
}

public static <T> AsonArray<T> serializeArray(@Nullable Object object) {
return AsonSerializer.get().serializeArray(object);
return serializeArray(object, false);
}

public static <T> AsonArray<T> serializeArray(@Nullable Object object, boolean recursive) {
return AsonSerializer.get().serializeArray(object, recursive);
}

public static <T> AsonArray<T> serializeList(@Nullable List<T> object) {
return AsonSerializer.get().serializeList(object);
return serializeList(object, false);
}

public static <T> AsonArray<T> serializeList(@Nullable List<T> object, boolean recursive) {
return AsonSerializer.get().serializeList(object, recursive);
}

public static <T> T deserialize(@Nullable String json, @NotNull Class<T> cls) {
return deserialize(json, cls, false);
}

public static <T> T deserialize(@Nullable String json, @NotNull Class<T> cls, boolean recursive) {
if (isJsonArray(json)) {
AsonArray ason = new AsonArray(json);
return AsonSerializer.get().deserializeArray(ason, cls);
return AsonSerializer.get().deserializeArray(ason, cls, recursive);
} else {
Ason ason = new Ason(json);
return AsonSerializer.get().deserialize(ason, cls);
return AsonSerializer.get().deserialize(ason, cls, recursive);
}
}

public static <T> T deserialize(@Nullable Ason json, @NonNls Class<T> cls) {
return AsonSerializer.get().deserialize(json, cls);
return deserialize(json, cls, false);
}

public static <T> T deserialize(@Nullable Ason json, @NonNls Class<T> cls, boolean recursive) {
return AsonSerializer.get().deserialize(json, cls, recursive);
}

public static <T> T deserialize(@Nullable AsonArray json, @NonNls Class<T> cls) {
return AsonSerializer.get().deserializeArray(json, cls);
return deserialize(json, cls, false);
}

public static <T> T deserialize(@Nullable AsonArray json, @NonNls Class<T> cls,
boolean recursive) {
return AsonSerializer.get().deserializeArray(json, cls, recursive);
}

public static <T> List<T> deserializeList(@Nullable String json, @NotNull Class<T> cls) {
return deserializeList(json, cls, false);
}

public static <T> List<T> deserializeList(@Nullable String json, @NotNull Class<T> cls,
boolean recursive) {
AsonArray array = new AsonArray(json);
return AsonSerializer.get().deserializeList(array, cls);
return AsonSerializer.get().deserializeList(array, cls, recursive);
}

public static <T> List<T> deserializeList(@Nullable AsonArray json, @NotNull Class<T> cls) {
return AsonSerializer.get().deserializeList(json, cls);
return deserializeList(json, cls, false);
}

private Ason putInternal(JSONArray intoArray, JSONObject intoObject, String key, Object value) {
public static <T> List<T> deserializeList(@Nullable AsonArray json, @NotNull Class<T> cls,
boolean recursive) {
return AsonSerializer.get().deserializeList(json, cls, recursive);
}

private void putInternal(JSONArray intoArray, JSONObject intoObject, String key, Object value) {
invalidateLoadedFields();
if (value == null || JSONObject.NULL.equals(value) || JSONObject.NULL == value) {
json.put(key, JSONObject.NULL);
return this;
} else if (isPrimitive(value) || value instanceof JSONObject || value instanceof JSONArray) {
if (value instanceof Byte) {
value = ((Byte) value).intValue();
Expand All @@ -123,7 +159,6 @@ private Ason putInternal(JSONArray intoArray, JSONObject intoObject, String key,
} else {
putInternal(intoArray, intoObject, key, serializer.serialize(value));
}
return this;
}

public Ason putNull(@NotNull String key) {
Expand Down Expand Up @@ -442,4 +477,8 @@ public String toString(int indentSpaces) {
public <T> T deserialize(@NonNls Class<T> cls) {
return deserialize(this, cls);
}

public <T> T deserialize(@NonNls Class<T> cls, boolean recursive) {
return deserialize(this, cls, recursive);
}
}
Loading

0 comments on commit 001d791

Please sign in to comment.