public class JsonReader extends Object implements Closeable
JsonReader.objectToJava(String json)
. This will
return a typed Java object graph.JsonReader.jsonToMaps(String json)
. This will
return an untyped object representation of the JSON String as a Map of Maps, where
the fields are the Map keys, and the field values are the associated Map's values. You can
call the JsonWriter.objectToJava() method with the returned Map, and it will serialize
the Graph into the identical JSON stream from which it was read.
JsonReader(InputStream in)
and then call
readObject()
. Cast the return value of readObject() to the Java class that was the root of
the graph.
JsonReader(InputStream in, true)
and then call
readObject()
. The return value will be a Map of Maps.
Modifier and Type | Class and Description |
---|---|
static class |
JsonReader.BigDecimalReader |
static class |
JsonReader.BigIntegerReader |
static class |
JsonReader.CalendarReader |
static interface |
JsonReader.ClassFactory |
static class |
JsonReader.ClassReader |
static class |
JsonReader.CollectionFactory
Use to create new instances of collection interfaces (needed for empty collections)
|
static class |
JsonReader.DateReader |
static interface |
JsonReader.JsonClassReader |
static class |
JsonReader.LocaleReader |
static class |
JsonReader.MapFactory
Use to create new instances of Map interfaces (needed for empty Maps)
|
static class |
JsonReader.SqlDateReader |
static class |
JsonReader.StringBufferReader |
static class |
JsonReader.StringBuilderReader |
static class |
JsonReader.StringReader |
static class |
JsonReader.TimestampReader |
static class |
JsonReader.TimeZoneReader |
Modifier and Type | Field and Description |
---|---|
static int |
MAX_CODE_POINT |
static char |
MIN_HIGH_SURROGATE |
static char |
MIN_LOW_SURROGATE |
static int |
MIN_SUPPLEMENTARY_CODE_POINT |
Constructor and Description |
---|
JsonReader() |
JsonReader(InputStream in) |
JsonReader(InputStream in,
boolean noObjects) |
Modifier and Type | Method and Description |
---|---|
static void |
addNotCustomReader(Class c) |
static void |
addReader(Class c,
JsonReader.JsonClassReader reader) |
protected void |
assignField(LinkedList<JsonObject<String,Object>> stack,
JsonObject jsonObj,
Field field,
Object rhs)
Map Json Map object field to Java object field.
|
static void |
assignInstantiator(Class c,
JsonReader.ClassFactory f)
For difficult to instantiate classes, you can add your own ClassFactory
which will be called when the passed in class 'c' is encountered.
|
static BigDecimal |
bigDecimalFrom(Object value) |
static BigInteger |
bigIntegerFrom(Object value) |
void |
close() |
protected Object |
convertMapsToObjects(JsonObject<String,Object> root)
Walk a JsonObject (Map of String keys to values) and return the
Java object equivalent filled in as best as possible (everything
except unresolved reference fields or unresolved array/collection elements).
|
protected Object |
convertParsedMapsToJava(JsonObject root)
This method converts a root Map, (which contains nested Maps
and so forth representing a Java Object graph), to a Java
object instance.
|
protected Object |
createJavaObjectInstance(Class clazz,
JsonObject jsonObj)
This method creates a Java Object instance based on the passed in parameters.
|
static Class |
getRawType(Type t) |
static boolean |
isPrimitive(Class c) |
Object |
jsonObjectsToJava(JsonObject root)
Convert a root JsonObject that represents parsed JSON, into
an actual Java object.
|
static Object |
jsonToJava(String json)
Convert the passed in JSON string into a Java object graph.
|
static Map |
jsonToMaps(String json)
Convert the passed in JSON string into a Java object graph
that consists solely of Java Maps where the keys are the
fields and the values are primitives or other Maps (in the
case of objects).
|
protected static Object |
readIfMatching(Object o,
Class compType,
LinkedList<JsonObject<String,Object>> stack) |
Object |
readObject()
Finite State Machine (FSM) used to parse the JSON input into
JsonObject's (Maps).
|
static Object |
toJava(String json)
Deprecated.
|
static Map |
toMaps(String json)
Deprecated.
|
protected void |
traverseArray(LinkedList<JsonObject<String,Object>> stack,
JsonObject<String,Object> jsonObj)
Traverse the JsonObject associated to an array (of any type).
|
protected void |
traverseCollection(LinkedList<JsonObject<String,Object>> stack,
JsonObject jsonObj)
Process java.util.Collection and it's derivatives.
|
protected void |
traverseCollectionNoObj(LinkedList<JsonObject<String,Object>> stack,
JsonObject jsonObj)
Process java.util.Collection and it's derivatives.
|
protected void |
traverseFields(LinkedList<JsonObject<String,Object>> stack,
JsonObject<String,Object> jsonObj)
Walk the Java object fields and copy them from the JSON object to the Java object, performing
any necessary conversions on primitives, or deep traversals for field assignments to other objects,
arrays, Collections, or Maps.
|
protected void |
traverseFieldsNoObj(LinkedList<JsonObject<String,Object>> stack,
JsonObject<String,Object> jsonObj) |
protected void |
traverseMap(LinkedList<JsonObject<String,Object>> stack,
JsonObject<String,Object> jsonObj)
Process java.util.Map and it's derivatives.
|
public static final int MAX_CODE_POINT
public static final int MIN_SUPPLEMENTARY_CODE_POINT
public static final char MIN_LOW_SURROGATE
public static final char MIN_HIGH_SURROGATE
public JsonReader()
public JsonReader(InputStream in)
public JsonReader(InputStream in, boolean noObjects)
public static void assignInstantiator(Class c, JsonReader.ClassFactory f)
public static BigInteger bigIntegerFrom(Object value) throws IOException
IOException
- if the input is something that cannot be converted to a BigInteger.public static BigDecimal bigDecimalFrom(Object value) throws IOException
IOException
- if the input is something that cannot be converted to a BigDecimal.public static void addReader(Class c, JsonReader.JsonClassReader reader)
public static void addNotCustomReader(Class c)
protected static Object readIfMatching(Object o, Class compType, LinkedList<JsonObject<String,Object>> stack) throws IOException
IOException
@Deprecated public static Object toJava(String json)
json
- String JSON inputpublic static Object jsonToJava(String json) throws IOException
json
- String JSON inputIOException
- If an I/O error occurs@Deprecated public static Map toMaps(String json)
json
- String JSON inputpublic static Map jsonToMaps(String json) throws IOException
json
- String JSON inputIOException
- If an I/O error occurspublic Object readObject() throws IOException
IOException
- for stream errors or parsing errors.public Object jsonObjectsToJava(JsonObject root) throws IOException
root
- JsonObject instance that was the root object from the
JSON input that was parsed in an earlier call to JsonReader.IOException
protected Object convertParsedMapsToJava(JsonObject root) throws IOException
root
- JsonObject instance that was the root object from the
JSON input that was parsed in an earlier call to JsonReader.IOException
protected Object convertMapsToObjects(JsonObject<String,Object> root) throws IOException
root
- JsonObject reference to a Map-of-Maps representation of the JSON
input after it has been completely read.IOException
- for stream errors or parsing errors.protected void traverseArray(LinkedList<JsonObject<String,Object>> stack, JsonObject<String,Object> jsonObj) throws IOException
stack
- a Stack (LinkedList) used to support graph traversal.jsonObj
- a Map-of-Map representation of the JSON input stream.IOException
- for stream errors or parsing errors.protected void traverseCollectionNoObj(LinkedList<JsonObject<String,Object>> stack, JsonObject jsonObj) throws IOException
stack
- a Stack (LinkedList) used to support graph traversal.jsonObj
- a Map-of-Map representation of the JSON input stream.IOException
- for stream errors or parsing errors.protected void traverseCollection(LinkedList<JsonObject<String,Object>> stack, JsonObject jsonObj) throws IOException
jsonObj
- a Map-of-Map representation of the JSON input stream.IOException
- for stream errors or parsing errors.protected void traverseMap(LinkedList<JsonObject<String,Object>> stack, JsonObject<String,Object> jsonObj) throws IOException
stack
- a Stack (LinkedList) used to support graph traversal.jsonObj
- a Map-of-Map representation of the JSON input stream.IOException
- for stream errors or parsing errors.protected void traverseFieldsNoObj(LinkedList<JsonObject<String,Object>> stack, JsonObject<String,Object> jsonObj) throws IOException
IOException
protected void traverseFields(LinkedList<JsonObject<String,Object>> stack, JsonObject<String,Object> jsonObj) throws IOException
stack
- Stack (LinkedList) used for graph traversal.jsonObj
- a Map-of-Map representation of the current object being examined (containing all fields).IOException
protected void assignField(LinkedList<JsonObject<String,Object>> stack, JsonObject jsonObj, Field field, Object rhs) throws IOException
stack
- Stack (LinkedList) used for graph traversal.jsonObj
- a Map-of-Map representation of the current object being examined (containing all fields).field
- a Java Field object representing where the jsonObj should be converted and stored.rhs
- the JSON value that will be converted and stored in the 'field' on the associated
Java target object.IOException
- for stream errors or parsing errors.protected Object createJavaObjectInstance(Class clazz, JsonObject jsonObj) throws IOException
clazz
- Instance will be create of this class.jsonObj
- Map-of-Map representation of object to create.IOException
- for stream errors or parsing errors.public static boolean isPrimitive(Class c)
public void close()
close
in interface Closeable
close
in interface AutoCloseable
Copyright © 2014. All rights reserved.