diff --git a/README.md b/README.md index e3de386..7da4c63 100644 --- a/README.md +++ b/README.md @@ -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' } ``` \ No newline at end of file diff --git a/src/main/java/com/github/webee/json/Utils.java b/src/main/java/com/github/webee/json/Utils.java index cc4d406..fd2bda0 100644 --- a/src/main/java/com/github/webee/json/Utils.java +++ b/src/main/java/com/github/webee/json/Utils.java @@ -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; } @@ -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) 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) 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; } }