From 97f602a547715dbce0bf11b1d8c864af44962b98 Mon Sep 17 00:00:00 2001 From: miktim Date: Mon, 17 Jun 2024 14:35:40 +0300 Subject: [PATCH] 2.0.3 --- README | 16 ++++++++++++---- dist/{json-2.0.2.jar => json-2.0.3.jar} | Bin 18229 -> 18363 bytes src/org/miktim/json/JSON.java | 10 +++++----- src/org/miktim/json/JSONObject.java | 19 +++++++++++++++---- test/json/JSONTest.java | 17 +++++++++++++---- 5 files changed, 45 insertions(+), 17 deletions(-) rename dist/{json-2.0.2.jar => json-2.0.3.jar} (51%) diff --git a/README b/README index cadd350..2f7e2e5 100644 --- a/README +++ b/README @@ -62,8 +62,9 @@ Overview: JSON normalize() throws IOException, ParseException; // not required to generate JSON text - String gen(String memberName, int... indices); // stringify value or array element - String toString(); // overridden, stringify JSON object + String toString(); // overridden, stringify JSON object + String toString(String memberName, int... indices); + // stringify member or array element Class JSONAdapter; @@ -84,8 +85,8 @@ Overview: Unloads/loads the accessible fields (properties) of the Java object to/from the JSON object. - Java final, interface, abstract, transient, strict fields are ignored; - - see JSON set/get/cast rules for Java object fields in the notes for JSON object - and JSONAdapter. + - see JSON set/get/cast rules for Java object fields in the notes for JSON object and JSONAdapter; + - arrays and collections of objects must be managed using replacer/reviewer. Constant: static final Object IGNORED; // returns from replacer/reviver to skip the field @@ -97,12 +98,19 @@ Overview: // convertible object parameters must be initialized protected Object replacer(String name, Object value); // first call with object class name and empty JSON object as value + public String toJSONText() + throws IllegalArgumentException, IllegalAccessException + // returns JSON text as one line + Object fromJSON(Object jsonObj) throws IllegalArgumentException, IllegalAccessException; // returns this object // convertible object parameters must be initialized protected Object reviver(String name, Object value); // first call with object class name and obj argument as value + public Object fromJSONText(String jsonText) + throws IOException, ParseException, IllegalArgumentException, IllegalAccessException + static final boolean isClassName(String name); protected T castMember(String memberName, JSON jsonObj, T sample); // returns the sample if JSON member does not exists diff --git a/dist/json-2.0.2.jar b/dist/json-2.0.3.jar similarity index 51% rename from dist/json-2.0.2.jar r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java index a5b96a4..6ba8181 100644 --- a/src/org/miktim/json/JSON.java +++ b/src/org/miktim/json/JSON.java @@ -69,17 +69,17 @@ public JSON(Object... members) throws IndexOutOfBoundsException { } } - public String gen() { - return generate(this); - } +// public String generate() { +// return JSON.generate(this); +// } - public String gen(String memberName, int... indices) { + public String toString(String memberName, int... indices) { return JSON.generate(get(memberName, indices)); } @Override public String toString() { - return gen(); + return JSON.generate(this); } public List listNames() { diff --git a/src/org/miktim/json/JSONObject.java b/src/org/miktim/json/JSONObject.java index 3646de3..d1d48c2 100644 --- a/src/org/miktim/json/JSONObject.java +++ b/src/org/miktim/json/JSONObject.java @@ -10,8 +10,10 @@ */ package org.miktim.json; +import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.text.ParseException; import java.util.Arrays; import java.util.LinkedHashMap; @@ -23,17 +25,26 @@ public Object toJSON() throws IllegalArgumentException, IllegalAccessException { return toJSON(this); } - + + public String toJSONText() throws IllegalArgumentException, IllegalAccessException { + return JSON.generate(toJSON()); + } + protected Object replacer(String fldName, Object value) { return value; } - public Object fromJSON(Object obj) + public Object fromJSON(Object jsonObj) throws IllegalArgumentException, IllegalAccessException { - fromJSON(this, obj); + fromJSON(this, jsonObj); return this; } - + + public Object fromJSONText(String jsonText) + throws IOException, ParseException, IllegalArgumentException, IllegalAccessException { + return fromJSON(JSON.parse(jsonText)); + } + @SuppressWarnings("unchecked") protected T castMember(String memberName, JSON jsonObj, T sample) { if (jsonObj.exists(memberName)) { diff --git a/test/json/JSONTest.java b/test/json/JSONTest.java index 65a6bbc..d3efb43 100644 --- a/test/json/JSONTest.java +++ b/test/json/JSONTest.java @@ -11,6 +11,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Date; +import java.util.HashMap; import json.A; import org.miktim.json.JSON; import org.miktim.json.JSONAdapter; @@ -122,15 +123,23 @@ public static void main(String[] args) throws Exception { i = json.getNumber("array", 1, 3).intValue(); log(i); - log("\n\rTest generator with other Java objects (ArrayList with Array, Date and File entries):"); + log("\n\rTest generator with other Java objects:"); + log(" HashMap with int[3], Date and File entries:"); + HashMap hashMap = new HashMap<>(); + hashMap.put("int[]",new int[3]); + hashMap.put("Date",new Date()); + hashMap.put("File", new File(path, "json.json")); + String s = JSON.generate(hashMap); + log(s); + log(" ArrayList with int[3], Date and File entries:"); ArrayList arrayList = new ArrayList<>(); - arrayList.add(new int[2]); + arrayList.add(new int[3]); arrayList.add(new Date()); arrayList.add(new File(path, "json.json")); - String s = JSON.generate(arrayList); + s = JSON.generate(arrayList); log(s); Object obj = JSON.parse(s); - log("is Array?: " + obj.getClass().isArray()); + log("is Array?: " + (obj instanceof Object[]));//obj.getClass().isArray()); log("\n\rTest examples:"); // examples from RFC 8259 https://datatracker.ietf.org/doc/rfc8259/?include_text=1