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

Commit

Permalink
1.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidan Follestad committed Feb 27, 2017
1 parent 5fda57a commit d1f327c
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .idea/modules/ason.iml

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

2 changes: 1 addition & 1 deletion .idea/modules/ason_main.iml

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

2 changes: 1 addition & 1 deletion .idea/modules/ason_test.iml

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

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The dependency is available via jCenter.
```Gradle
dependencies {
...
compile 'com.afollestad:ason:1.4.3'
compile 'com.afollestad:ason:1.4.4'
}
```

Expand All @@ -64,7 +64,7 @@ Since Android includes `org.json` classes, you'll want to exclude the copies pro
```Gradle
dependencies {
...
compile('com.afollestad:ason:1.4.3') {
compile('com.afollestad:ason:1.4.4') {
exclude group: 'org.json', module: 'json'
}
}
Expand All @@ -78,7 +78,7 @@ Android, make sure you also exclude org.json as shown in the section above.*
```Gradle
dependencies {
...
compile('com.afollestad:ason:1.4.3') {
compile('com.afollestad:ason:1.4.4') {
exclude group: 'com.intellij', module: 'annotations'
}
}
Expand All @@ -90,7 +90,7 @@ dependencies {
<dependency>
<groupId>com.afollestad</groupId>
<artifactId>ason</artifactId>
<version>1.4.3</version>
<version>1.4.4</version>
<type>pom</type>
</dependency>
```
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.afollestad'
version '1.4.3'
version '1.4.4'

apply plugin: 'java'
apply plugin: 'idea'
Expand Down Expand Up @@ -34,7 +34,7 @@ publish {
userOrg = 'drummer-aidan'
groupId = 'com.afollestad'
artifactId = 'ason'
publishVersion = '1.4.3'
publishVersion = '1.4.4'
website = 'https://github.com/afollestad/ason'
}

Expand Down
18 changes: 16 additions & 2 deletions src/main/java/com/afollestad/ason/Ason.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ private Ason putInternal(JSONArray intoArray,
try {
if (value == null) {
return this;
} else if (JSONObject.NULL.equals(value)
|| JSONObject.NULL == value) {
json.put(key, JSONObject.NULL);
return this;
} else if (isPrimitive(value) ||
value instanceof JSONObject ||
value instanceof JSONArray) {
Expand Down Expand Up @@ -82,10 +86,14 @@ private Ason putInternal(JSONArray intoArray,
return this;
}

public Ason putNull(@NotNull String key) {
return put(key, JSONObject.NULL);
}

public Ason put(@NotNull String key, Object... values) {
Object insertObject;
if (values == null || values.length == 1) {
insertObject = values != null ? values[0] : null;
insertObject = values != null ? values[0] : JSONObject.NULL;
} else {
JSONArray newArray = new JSONArray();
for (Object value : values) {
Expand Down Expand Up @@ -146,6 +154,9 @@ public Ason remove(@NotNull String key) {
}
if (result == null) {
return defaultValue;
} else if (JSONObject.NULL.equals(result)
|| JSONObject.NULL == result) {
return defaultValue;
} else if (result instanceof JSONObject) {
result = new Ason((JSONObject) result);
} else if (result instanceof JSONArray) {
Expand Down Expand Up @@ -278,7 +289,10 @@ public boolean equal(@NotNull String key, @Nullable Object value) {
}

public boolean isNull(String key) {
return get(key) == null;
Object value = get(key);
return value == null
|| JSONObject.NULL.equals(value)
|| JSONObject.NULL == value;
}

@Override public int hashCode() {
Expand Down
17 changes: 16 additions & 1 deletion src/test/java/com/afollestad/ason/AsonTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.afollestad.ason;

import org.json.JSONObject;
import org.junit.Test;
import sun.text.resources.no.JavaTimeSupplementary_no;

import java.lang.reflect.Field;
import java.util.ArrayList;
Expand All @@ -22,14 +24,27 @@ public class AsonTest {
}
}

@SuppressWarnings({"FieldCanBeLocal", "unused"}) private List<Ason> listField;
@SuppressWarnings({"FieldCanBeLocal", "unused", "MismatchedQueryAndUpdateOfCollection"}) private List<Ason> listField;

@Test public void generic_list_type_test() throws Exception {
listField = new ArrayList<>(0);
Field field = AsonTest.class.getDeclaredField("listField");
assertEquals(Ason.class, listGenericType(field));
}

@Test public void json_null_test() {
Ason ason = new Ason()
.putNull("test")
.put("test2", null);
assertTrue(ason.isNull("test"));
assertTrue(ason.isNull("test2"));
assertEquals(null, ason.get("test"));
assertEquals(null, ason.get("test2"));
JSONObject stock = ason.toStockJson();
assertEquals(JSONObject.NULL, stock.get("test"));
assertEquals(JSONObject.NULL, stock.get("test2"));
}

@Test public void test_is_number_true() {
assertTrue(isNumber("1234"));
assertTrue(isNumber("67891023231"));
Expand Down

0 comments on commit d1f327c

Please sign in to comment.