Skip to content

Commit

Permalink
update Utils and getType.
Browse files Browse the repository at this point in the history
  • Loading branch information
webee committed Dec 17, 2016
1 parent cc9edaa commit b33ba07
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ To install the library add:
maven { url "https://jitpack.io" }
}
dependencies {
compile 'com.github.webee:java-json-api:v2.0.0'
compile 'com.github.webee:java-json-api:v2.1.0'
}
```
43 changes: 26 additions & 17 deletions src/main/java/com/github/webee/json/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public static JSONType getType(Object value) {
return JSONType.Object;
} else if (value instanceof JSONArray) {
return JSONType.Array;
} else if (value instanceof Map) {
return JSONType.Object;
} else if (value instanceof Object[]) {
return JSONType.Array;
}
return null;
}
Expand Down Expand Up @@ -99,24 +103,29 @@ public static Object resolveValue(Object value) {
}

public static Object resolveValue(Object value, JSONType t) {
if (t == null) {
if (value instanceof Map) {
return Utils.objectToMap((Map<String, Object>) value);
} else if (value instanceof Object[]) {
return Utils.arrayToObjects((Object[]) value);
if (t != null) {
switch (t) {
case Object:
if (value instanceof JSONObject) {
return Utils.objectToMap((JSONObject) value);
} else if (value instanceof Map) {
return Utils.objectToMap((Map<String, Object>) value);
}
break;
case Array:
if (value instanceof JSONArray) {
return Utils.arrayToObjects((JSONArray) value);
} else if (value instanceof Object[]) {
return Utils.arrayToObjects((Object[]) value);
}
break;
case Null:
return null;
default:
return value;
}
return null;
}

switch (t) {
case Object:
return Utils.objectToMap((JSONObject) value);
case Array:
return Utils.arrayToObjects((JSONArray) value);
case Null:
return null;
default:
return value;
}
// FIXME: some type should be ignored.
return null;
}
}

0 comments on commit b33ba07

Please sign in to comment.