diff --git a/accessors-smart/pom.xml b/accessors-smart/pom.xml index b3c9306..ef87765 100644 --- a/accessors-smart/pom.xml +++ b/accessors-smart/pom.xml @@ -50,7 +50,6 @@ limitations under the License. UTF-8 - 10 1.8 1.8 diff --git a/json-smart-action/pom.xml b/json-smart-action/pom.xml index 8b607d5..c2acc58 100644 --- a/json-smart-action/pom.xml +++ b/json-smart-action/pom.xml @@ -41,7 +41,6 @@ UTF-8 - 10 1.8 1.8 5.12.1 diff --git a/json-smart-action/src/main/java/net/minidev/json/actions/ElementRemover.java b/json-smart-action/src/main/java/net/minidev/json/actions/ElementRemover.java index 5fda519..898f9d1 100644 --- a/json-smart-action/src/main/java/net/minidev/json/actions/ElementRemover.java +++ b/json-smart-action/src/main/java/net/minidev/json/actions/ElementRemover.java @@ -36,7 +36,7 @@ public ElementRemover(Map elementsToRemove) { elementsToRemove == null ? Collections.emptyMap() : elementsToRemove; } - public ElementRemover(JSONObject elementsToRemove) { + public ElementRemover(JSONObject elementsToRemove) { this.elementsToRemove = elementsToRemove == null ? Collections.emptyMap() : elementsToRemove; } diff --git a/json-smart-action/src/main/java/net/minidev/json/actions/PathLocator.java b/json-smart-action/src/main/java/net/minidev/json/actions/PathLocator.java index c0e1840..216076e 100644 --- a/json-smart-action/src/main/java/net/minidev/json/actions/PathLocator.java +++ b/json-smart-action/src/main/java/net/minidev/json/actions/PathLocator.java @@ -31,7 +31,7 @@ public class PathLocator { protected List pathsToFind; protected PathDelimiter pathDelimiter = new DotDelimiter().withAcceptDelimiterInNodeName(false); - public PathLocator(JSONArray pathsToFind) { + public PathLocator(JSONArray pathsToFind) { if (pathsToFind == null || pathsToFind.isEmpty()) { this.pathsToFind = Collections.emptyList(); } else { diff --git a/json-smart-action/src/main/java/net/minidev/json/actions/PathRemover.java b/json-smart-action/src/main/java/net/minidev/json/actions/PathRemover.java index 3ea6927..7aa4d9b 100644 --- a/json-smart-action/src/main/java/net/minidev/json/actions/PathRemover.java +++ b/json-smart-action/src/main/java/net/minidev/json/actions/PathRemover.java @@ -38,7 +38,7 @@ public class PathRemover { protected List pathsToRemove; - public PathRemover(JSONArray pathsToRemove) { + public PathRemover(JSONArray pathsToRemove) { if (pathsToRemove == null || pathsToRemove.isEmpty()) { this.pathsToRemove = Collections.emptyList(); } else { diff --git a/json-smart-action/src/main/java/net/minidev/json/actions/PathReplicator.java b/json-smart-action/src/main/java/net/minidev/json/actions/PathReplicator.java index d5b8f21..dd53322 100644 --- a/json-smart-action/src/main/java/net/minidev/json/actions/PathReplicator.java +++ b/json-smart-action/src/main/java/net/minidev/json/actions/PathReplicator.java @@ -41,7 +41,7 @@ public class PathReplicator { protected List pathsToCopy; - public PathReplicator(JSONArray pathsToCopy) { + public PathReplicator(JSONArray pathsToCopy) { if (pathsToCopy == null || pathsToCopy.isEmpty()) { this.pathsToCopy = Collections.emptyList(); } else { diff --git a/json-smart-action/src/main/java/net/minidev/json/actions/PathsRetainer.java b/json-smart-action/src/main/java/net/minidev/json/actions/PathsRetainer.java index 824d884..8a13dbf 100644 --- a/json-smart-action/src/main/java/net/minidev/json/actions/PathsRetainer.java +++ b/json-smart-action/src/main/java/net/minidev/json/actions/PathsRetainer.java @@ -35,7 +35,7 @@ public class PathsRetainer { protected List pathsToRetain; protected PathDelimiter pathDelimiter = new DotDelimiter().withAcceptDelimiterInNodeName(false); - public PathsRetainer(JSONArray pathsToRetain) { + public PathsRetainer(JSONArray pathsToRetain) { if (pathsToRetain == null || pathsToRetain.isEmpty()) { this.pathsToRetain = Collections.emptyList(); } else { diff --git a/json-smart-action/src/main/java/net/minidev/json/actions/navigate/CopyPathsAction.java b/json-smart-action/src/main/java/net/minidev/json/actions/navigate/CopyPathsAction.java index f292bc9..1ace2b8 100644 --- a/json-smart-action/src/main/java/net/minidev/json/actions/navigate/CopyPathsAction.java +++ b/json-smart-action/src/main/java/net/minidev/json/actions/navigate/CopyPathsAction.java @@ -31,8 +31,8 @@ public class CopyPathsAction implements JSONNavigateAction { protected Stack destNodeStack; @Override - public boolean start(JSONObject source, Collection pathsToCopy) { - if (source == null) { + public boolean start(JSONObject objectToNavigate, Collection pathsToCopy) { + if (objectToNavigate == null) { destTree = null; return false; } diff --git a/json-smart-action/src/main/java/net/minidev/json/actions/navigate/JSONNavigateAction.java b/json-smart-action/src/main/java/net/minidev/json/actions/navigate/JSONNavigateAction.java index f06a6ca..c380980 100644 --- a/json-smart-action/src/main/java/net/minidev/json/actions/navigate/JSONNavigateAction.java +++ b/json-smart-action/src/main/java/net/minidev/json/actions/navigate/JSONNavigateAction.java @@ -12,4 +12,4 @@ * @author adoneitan@gmail.com * @since 15 June 2016. */ -public interface JSONNavigateAction extends NavigateAction {} +public interface JSONNavigateAction extends NavigateAction, JSONArray> {} diff --git a/json-smart-action/src/main/java/net/minidev/json/actions/navigate/JSONNavigator.java b/json-smart-action/src/main/java/net/minidev/json/actions/navigate/JSONNavigator.java index 79fab41..c2fdc91 100644 --- a/json-smart-action/src/main/java/net/minidev/json/actions/navigate/JSONNavigator.java +++ b/json-smart-action/src/main/java/net/minidev/json/actions/navigate/JSONNavigator.java @@ -8,7 +8,7 @@ * @author adoneitan@gmail.com * @since 15 June 2016. */ -public class JSONNavigator extends TreeNavigator { +public class JSONNavigator extends TreeNavigator, JSONArray> { public JSONNavigator(JSONNavigateAction action, List pathsToNavigate) { super(action, pathsToNavigate); diff --git a/json-smart-action/src/main/java/net/minidev/json/actions/traverse/JSONTraverseAction.java b/json-smart-action/src/main/java/net/minidev/json/actions/traverse/JSONTraverseAction.java index e713215..b6b9586 100644 --- a/json-smart-action/src/main/java/net/minidev/json/actions/traverse/JSONTraverseAction.java +++ b/json-smart-action/src/main/java/net/minidev/json/actions/traverse/JSONTraverseAction.java @@ -10,4 +10,4 @@ * * @author adoneitan@gmail.com */ -public interface JSONTraverseAction extends TreeTraverseAction {} +public interface JSONTraverseAction extends TreeTraverseAction, JSONArray> {} diff --git a/json-smart-action/src/main/java/net/minidev/json/actions/traverse/JSONTraverser.java b/json-smart-action/src/main/java/net/minidev/json/actions/traverse/JSONTraverser.java index 18bcc30..6a801a5 100644 --- a/json-smart-action/src/main/java/net/minidev/json/actions/traverse/JSONTraverser.java +++ b/json-smart-action/src/main/java/net/minidev/json/actions/traverse/JSONTraverser.java @@ -18,7 +18,7 @@ * * @author adoneitan@gmail.com */ -public class JSONTraverser extends TreeTraverser { +public class JSONTraverser extends TreeTraverser, JSONArray> { public JSONTraverser(JSONTraverseAction action) { super(action, new DotDelimiter()); } diff --git a/json-smart-action/src/test/java/net/minidev/json/test/actions/PathLocatorTest.java b/json-smart-action/src/test/java/net/minidev/json/test/actions/PathLocatorTest.java index 25afb1b..62c8001 100644 --- a/json-smart-action/src/test/java/net/minidev/json/test/actions/PathLocatorTest.java +++ b/json-smart-action/src/test/java/net/minidev/json/test/actions/PathLocatorTest.java @@ -141,7 +141,7 @@ private PathLocator switchKeyToRemove(Object keysToFind) { return new PathLocator((String[]) null); } else if (keysToFind == null && m % 4 == 2) { // System.out.println("cast to JSONArray"); - return new PathLocator((JSONArray) null); + return new PathLocator((JSONArray) null); } else if (keysToFind == null && m % 4 == 3) { // System.out.println("cast to List"); return new PathLocator((List) null); @@ -150,7 +150,7 @@ private PathLocator switchKeyToRemove(Object keysToFind) { } else if (keysToFind instanceof String[]) { return new PathLocator((String[]) keysToFind); } else if (keysToFind instanceof JSONArray) { - return new PathLocator((JSONArray) keysToFind); + return new PathLocator((JSONArray) keysToFind); } else if (keysToFind instanceof List) { return new PathLocator((List) keysToFind); } else { diff --git a/json-smart-action/src/test/java/net/minidev/json/test/actions/PathRemoverTest.java b/json-smart-action/src/test/java/net/minidev/json/test/actions/PathRemoverTest.java index 9a4358e..93364b3 100644 --- a/json-smart-action/src/test/java/net/minidev/json/test/actions/PathRemoverTest.java +++ b/json-smart-action/src/test/java/net/minidev/json/test/actions/PathRemoverTest.java @@ -129,7 +129,7 @@ private PathRemover switchKeyToRemove(Object keyToRemove) { return new PathRemover((String[]) null); } else if (keyToRemove == null && m % 4 == 2) { // System.out.println("cast to JSONArray"); - return new PathRemover((JSONArray) null); + return new PathRemover((JSONArray) null); } else if (keyToRemove == null && m % 4 == 3) { // System.out.println("cast to List"); return new PathRemover((List) null); @@ -138,7 +138,7 @@ private PathRemover switchKeyToRemove(Object keyToRemove) { } else if (keyToRemove instanceof String[]) { return new PathRemover((String[]) keyToRemove); } else if (keyToRemove instanceof JSONArray) { - return new PathRemover((JSONArray) keyToRemove); + return new PathRemover((JSONArray) keyToRemove); } else if (keyToRemove instanceof List) { return new PathRemover((List) keyToRemove); } else { diff --git a/json-smart-action/src/test/java/net/minidev/json/test/actions/PathReplicatorTest.java b/json-smart-action/src/test/java/net/minidev/json/test/actions/PathReplicatorTest.java index 2fe0657..6894b0a 100644 --- a/json-smart-action/src/test/java/net/minidev/json/test/actions/PathReplicatorTest.java +++ b/json-smart-action/src/test/java/net/minidev/json/test/actions/PathReplicatorTest.java @@ -184,7 +184,7 @@ private PathReplicator switchKeyToCopy(Object pathsToCopy) { return new PathReplicator((String[]) null); } else if (pathsToCopy == null && m % 4 == 2) { // System.out.println("cast to JSONArray"); - return new PathReplicator((JSONArray) null); + return new PathReplicator((JSONArray) null); } else if (pathsToCopy == null && m % 4 == 3) { // System.out.println("cast to List"); return new PathReplicator((List) null); @@ -193,7 +193,7 @@ private PathReplicator switchKeyToCopy(Object pathsToCopy) { } else if (pathsToCopy instanceof String[]) { return new PathReplicator((String[]) pathsToCopy); } else if (pathsToCopy instanceof JSONArray) { - return new PathReplicator((JSONArray) pathsToCopy); + return new PathReplicator((JSONArray) pathsToCopy); } else if (pathsToCopy instanceof List) { return new PathReplicator((List) pathsToCopy); } else { @@ -212,7 +212,7 @@ private PathReplicator switchKeyToCopy2(Object pathsToCopy) { return new PathReplicator((String[]) null); } else if (pathsToCopy == null && m % 4 == 2) { // System.out.println("cast to JSONArray"); - return new PathReplicator((JSONArray) null); + return new PathReplicator((JSONArray) null); } else if (pathsToCopy == null && m % 4 == 3) { // System.out.println("cast to List"); return new PathReplicator((List) null); @@ -221,7 +221,7 @@ private PathReplicator switchKeyToCopy2(Object pathsToCopy) { } else if (pathsToCopy instanceof String[]) { return new PathReplicator((String[]) pathsToCopy); } else if (pathsToCopy instanceof JSONArray) { - return new PathReplicator((JSONArray) pathsToCopy); + return new PathReplicator((JSONArray) pathsToCopy); } else if (pathsToCopy instanceof List) { return new PathReplicator((List) pathsToCopy); } else { diff --git a/json-smart-action/src/test/java/net/minidev/json/test/actions/PathsRetainerTest.java b/json-smart-action/src/test/java/net/minidev/json/test/actions/PathsRetainerTest.java index 16f18eb..f9b139e 100644 --- a/json-smart-action/src/test/java/net/minidev/json/test/actions/PathsRetainerTest.java +++ b/json-smart-action/src/test/java/net/minidev/json/test/actions/PathsRetainerTest.java @@ -155,7 +155,7 @@ private PathsRetainer switchKeyToRemove(Object keyToKeep) { return new PathsRetainer((String[]) null); } else if (keyToKeep == null && m % 4 == 2) { // System.out.println("cast to JSONArray"); - return new PathsRetainer((JSONArray) null); + return new PathsRetainer((JSONArray) null); } else if (keyToKeep == null && m % 4 == 3) { // System.out.println("cast to List"); return new PathsRetainer((List) null); @@ -164,7 +164,7 @@ private PathsRetainer switchKeyToRemove(Object keyToKeep) { } else if (keyToKeep instanceof String[]) { return new PathsRetainer((String[]) keyToKeep); } else if (keyToKeep instanceof JSONArray) { - return new PathsRetainer((JSONArray) keyToKeep); + return new PathsRetainer((JSONArray) keyToKeep); } else if (keyToKeep instanceof List) { return new PathsRetainer((List) keyToKeep); } else { diff --git a/json-smart/pom.xml b/json-smart/pom.xml index cbce688..e0a3131 100644 --- a/json-smart/pom.xml +++ b/json-smart/pom.xml @@ -56,7 +56,6 @@ limitations under the License. UTF-8 - 10 1.8 1.8 5.12.1 diff --git a/json-smart/src/main/java/net/minidev/json/JSONArray.java b/json-smart/src/main/java/net/minidev/json/JSONArray.java index 54c2b72..aa3a7d2 100644 --- a/json-smart/src/main/java/net/minidev/json/JSONArray.java +++ b/json-smart/src/main/java/net/minidev/json/JSONArray.java @@ -26,8 +26,8 @@ * @author FangYidong <fangyidong@yahoo.com.cn> * @author Uriel Chemouni <uchemouni@gmail.com> */ -public class JSONArray extends ArrayList - implements List, JSONAwareEx, JSONStreamAwareEx { +public class JSONArray extends ArrayList + implements List, JSONAwareEx, JSONStreamAwareEx { private static final long serialVersionUID = 9106884089231309568L; public JSONArray() {} @@ -87,7 +87,7 @@ public static void writeJSONString(List list, Appendable out) * @param element element to be appended to this array. * @return this */ - public JSONArray appendElement(Object element) { + public JSONArray appendElement(E element) { add(element); return this; } diff --git a/json-smart/src/main/java/net/minidev/json/JSONObject.java b/json-smart/src/main/java/net/minidev/json/JSONObject.java index ebab072..2d27842 100644 --- a/json-smart/src/main/java/net/minidev/json/JSONObject.java +++ b/json-smart/src/main/java/net/minidev/json/JSONObject.java @@ -26,7 +26,7 @@ * @author FangYidong <fangyidong@yahoo.com.cn> * @author Uriel Chemouni <uchemouni@gmail.com> */ -public class JSONObject extends HashMap implements JSONAwareEx, JSONStreamAwareEx { +public class JSONObject extends HashMap implements JSONAwareEx, JSONStreamAwareEx { private static final long serialVersionUID = -503443796854799292L; public JSONObject() { @@ -92,7 +92,7 @@ public static void writeJSONKV(String key, Object value, Appendable out, JSONSty * @param fieldValue value to be associated with the specified key * @return this */ - public JSONObject appendField(String fieldName, Object fieldValue) { + public JSONObject appendField(String fieldName, E fieldValue) { put(fieldName, fieldValue); return this; } @@ -145,7 +145,7 @@ public Number getAsNumber(String key) { * Allows creation of a JSONObject from a Map. After that, both the generated JSONObject and the * Map can be modified independently. */ - public JSONObject(Map map) { + public JSONObject(Map map) { super(map); } @@ -198,9 +198,21 @@ protected static JSONObject merge(JSONObject o1, Object o2, boolean overwrite) { throw new RuntimeException("JSON merge can not merge JSONObject with " + o2.getClass()); } + static class A { + int a; + + public int getA() { + return a; + } + + public void setA(int a) { + this.a = a; + } + } + private static JSONObject merge(JSONObject o1, JSONObject o2, boolean overwrite) { if (o2 == null) return o1; - for (String key : o1.keySet()) { + for (Object key : o1.keySet()) { Object value1 = o1.get(key); Object value2 = o2.get(key); if (value2 == null) continue; @@ -227,7 +239,7 @@ private static JSONObject merge(JSONObject o1, JSONObject o2, boolean overwrite) + " with " + value2.getClass().getName()); } - for (String key : o2.keySet()) { + for (Object key : o2.keySet()) { if (o1.containsKey(key)) continue; o1.put(key, o2.get(key)); }