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

Commit

Permalink
1.4.14
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 001d791 commit b00870b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 35 deletions.
16 changes: 7 additions & 9 deletions src/main/java/com/afollestad/ason/Ason.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
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 @@ -109,17 +107,17 @@ public static <T> T deserialize(@Nullable AsonArray json, @NonNls Class<T> cls)
return deserialize(json, cls, false);
}

public static <T> T deserialize(@Nullable AsonArray json, @NonNls Class<T> cls,
boolean recursive) {
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) {
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, recursive);
}
Expand All @@ -128,8 +126,8 @@ public static <T> List<T> deserializeList(@Nullable AsonArray json, @NotNull Cla
return deserializeList(json, cls, false);
}

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

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/afollestad/ason/AsonSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import org.json.JSONArray;
import org.json.JSONObject;

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

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/afollestad/ason/AsonArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void test_array_in_array() {
@Test
public void test_array_in_array_deserialize() {
AsonArray<Integer[]> parent =
new AsonArray<Integer[]>().add(new Integer[]{1, 2, 3, 4}, new Integer[]{5, 6, 7, 8});
new AsonArray<Integer[]>().add(new Integer[] {1, 2, 3, 4}, new Integer[] {5, 6, 7, 8});
assertEquals(2, parent.size());

Integer[] arrayOne = parent.get(0, Integer[].class);
Expand Down
39 changes: 17 additions & 22 deletions src/test/java/com/afollestad/ason/AsonSerializeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
import org.json.JSONObject;
import org.junit.Test;

/**
* @author Aidan Follestad (afollestad)
*/
/** @author Aidan Follestad (afollestad) */
public class AsonSerializeTest {

//
Expand All @@ -40,7 +38,7 @@ public void test_serialize() {

@Test
public void test_serialize_array() {
Person[] people = new Person[]{new Person(1, "Aidan", 22), new Person(2, "Nina", 22)};
Person[] people = new Person[] {new Person(1, "Aidan", 22), new Person(2, "Nina", 22)};
AsonArray<Person> json = Ason.serializeArray(people);

Ason one = json.getJsonObject(0);
Expand Down Expand Up @@ -97,15 +95,15 @@ public void test_put_array_serialize() {

@Test
public void test_primitive_serialize() {
int[] ids = new int[]{1, 2, 3, 4};
int[] ids = new int[] {1, 2, 3, 4};
AsonArray<Integer> array = Ason.serializeArray(ids);
assertEquals("[1,2,3,4]", array.toString());
}

@Test
public void test_serialize_with_array() {
Person2 person = new Person2(1);
person.family = new Person2[]{new Person2(2), new Person2(3), new Person2(4)};
person.family = new Person2[] {new Person2(2), new Person2(3), new Person2(4)};

Ason ason = Ason.serialize(person);
AsonArray<Person3> array = ason.get("family");
Expand Down Expand Up @@ -308,7 +306,7 @@ public void test_serialize_ason_object_array() {
@Test
public void test_serialize_array_list_wrong_method() {
try {
Ason.serialize(new int[]{1, 2, 3, 4});
Ason.serialize(new int[] {1, 2, 3, 4});
assertFalse("No exception thrown when using serialize() on array!", false);
} catch (IllegalArgumentException ignored) {
}
Expand All @@ -327,7 +325,7 @@ public void test_serialize_array_list_wrong_method() {

@Test
public void test_serialize_empty_array() {
AsonArray array = Ason.serializeArray(new int[]{});
AsonArray array = Ason.serializeArray(new int[] {});
assertTrue(array.isEmpty());
}

Expand Down Expand Up @@ -484,7 +482,7 @@ public void test_get_list_null() {
@Test
public void test_issue10_serialize() {
Issue10Example data = new Issue10Example();
data.item = new Object[]{1, 2, 3, 4};
data.item = new Object[] {1, 2, 3, 4};

Ason ason = Ason.serialize(data);
AsonArray<Integer> array = ason.get("item");
Expand All @@ -500,7 +498,7 @@ public void test_issue10_deserialize() {
Ason ason = new Ason("{\"item\": [1, 2, 3, 4]}");
Issue10Example result = Ason.deserialize(ason, Issue10Example.class);
Object[] array = (Object[]) result.item;
assertTrue(Arrays.equals(new Integer[]{1, 2, 3, 4}, array));
assertTrue(Arrays.equals(new Integer[] {1, 2, 3, 4}, array));
}

@Test
Expand Down Expand Up @@ -541,8 +539,8 @@ public void test_deserialize_all_nulls_to_primitive() {

@Test
public void test_deserialize_array_of_arrays() {
Integer[] one = new Integer[]{1, 2, 3, 4};
Integer[] two = new Integer[]{5, 6, 7, 8};
Integer[] one = new Integer[] {1, 2, 3, 4};
Integer[] two = new Integer[] {5, 6, 7, 8};
AsonArray<Integer[]> jsonArray = new AsonArray<Integer[]>().add(one, two);
Integer[][] matrix = AsonSerializer.get().deserializeArray(jsonArray, Integer[][].class);
assertNotNull(matrix);
Expand Down Expand Up @@ -606,8 +604,9 @@ public void test_deserialize_array_of_null_lists() {

@Test
public void test_recursive_deserialize() {
Ason ason = new Ason(
"{\"name\":\"Aidan\",\"power\":\"Flight\",\"_id\":2,\"age\":22,\"spouse\":{\"name\":\"Nina\",\"_id\":6,\"age\":22,\"spouse\":null}}");
Ason ason =
new Ason(
"{\"name\":\"Aidan\",\"power\":\"Flight\",\"_id\":2,\"age\":22,\"spouse\":{\"name\":\"Nina\",\"_id\":6,\"age\":22,\"spouse\":null}}");
Superhero person = ason.deserialize(Superhero.class, true);
assertEquals(person.name, "Aidan");
assertEquals(person.id, 2);
Expand All @@ -624,11 +623,9 @@ static class Person {
String name;
int age;
Person spouse;
@AsonIgnore
String gibberish = "Hello, world!";
@AsonIgnore String gibberish = "Hello, world!";

Person() {
}
Person() {}

Person(int id, String name, int age) {
this.id = id;
Expand All @@ -648,8 +645,7 @@ static class Person2 {

Person2[] family;

Person2() {
}
Person2() {}

Person2(int id) {
this();
Expand Down Expand Up @@ -679,8 +675,7 @@ private static class Superhero extends Person {

String power;

Superhero() {
}
Superhero() {}

Superhero(int id, String name, int age, String power) {
super(id, name, age);
Expand Down

0 comments on commit b00870b

Please sign in to comment.