public class JsonReader extends Object implements Closeable
JsonReader.jsonToJava(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.objectToJson() method with the returned Map, and it will serialize
the Graph into the equivalent 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 interface |
JsonReader.ClassFactory
Subclass this interface and create a class that will return a new instance of the
passed in Class (c).
|
static class |
JsonReader.CollectionFactory
Use to create new instances of collection interfaces (needed for empty collections)
|
static interface |
JsonReader.JsonClassReader
Implement this interface to add a custom JSON reader.
|
static interface |
JsonReader.JsonClassReaderBase
Deprecated.
|
static interface |
JsonReader.JsonClassReaderEx
Deprecated.
|
static class |
JsonReader.MapFactory
Use to create new instances of Map interfaces (needed for empty Maps).
|
static interface |
JsonReader.MissingFieldHandler
Used to react to fields missing when reading an object.
|
Modifier and Type | Field and Description |
---|---|
static String |
CLASSLOADER
If set, use the specified ClassLoader
|
static String |
CUSTOM_READER_MAP
If set, this maps class ==> CustomReader
|
static String |
FACTORIES
If set, this map will contain Factory classes for creating hard to instantiate objects.
|
static String |
FAIL_ON_UNKNOWN_TYPE
Will fail JSON parsing if 'type' class defined but is not on classpath.
|
static String |
JSON_READER
Pointer to 'this' (automatically placed in the Map)
|
static String |
MISSING_FIELD_HANDLER
If set, this object will be called when a field is present in the JSON but missing from the corresponding class
|
static String |
NOT_CUSTOM_READER_MAP
If set, this indicates that no custom reader should be used for the specified class ==> CustomReader
|
static String |
OBJECT_RESOLVER
Pointer to the current ObjectResolver (automatically placed in the Map)
|
static String |
TYPE_NAME_MAP
If set, this map will be used when reading @type values - allows shorthand abbreviations type names
|
static String |
UNKNOWN_OBJECT
What to do when an object is found and 'type' cannot be determined.
|
static String |
USE_MAPS
If set, the read-in JSON will be turned into a Map of Maps (JsonObject) representation
|
Constructor and Description |
---|
JsonReader()
Deprecated.
|
JsonReader(byte[] inp,
Map<String,Object> optionalArgs)
Deprecated.
|
JsonReader(byte[] inp,
Map<String,Object> optionalArgs,
int maxDepth)
Deprecated.
|
JsonReader(byte[] bytes,
ReadOptions readOptions)
Creates a json reader using custom read options
|
JsonReader(InputStream inputStream)
Deprecated.
|
JsonReader(InputStream inputStream,
boolean useMaps)
Deprecated.
|
JsonReader(InputStream inputStream,
boolean useMaps,
int maxDepth)
Deprecated.
|
JsonReader(InputStream inputStream,
int maxDepth)
Deprecated.
|
JsonReader(InputStream inputStream,
Map<String,Object> optionalArgs)
Deprecated.
|
JsonReader(InputStream inputStream,
Map<String,Object> optionalArgs,
int maxDepth)
Deprecated.
|
JsonReader(InputStream inp,
ReadOptions readOptions)
Creates a json reader using custom read options
|
JsonReader(InputStream input,
ReadOptions readOptions,
ReferenceTracker references) |
JsonReader(int maxDepth)
Deprecated.
|
JsonReader(Map<String,Object> optionalArgs)
Deprecated.
|
JsonReader(Map<String,Object> optionalArgs,
int maxDepth)
Deprecated.
|
JsonReader(ReadOptions options)
Use this constructor if you already have a JsonObject graph and want to parse it into
Java objects by calling jsonReader.jsonObjectsToJava(rootJsonObject) after constructing
the JsonReader.
|
JsonReader(String json)
Creates a json reader using default read options
|
JsonReader(String json,
Map<String,Object> optionalArgs)
Deprecated.
|
JsonReader(String json,
Map<String,Object> optionalArgs,
int maxDepth)
Deprecated.
|
JsonReader(String json,
ReadOptions readOptions)
Creates a json reader using custom read options
|
Modifier and Type | Method and Description |
---|---|
void |
addNotCustomReader(Class<?> c)
Deprecated.
use ReadOptionsBuilder.withNonCustomizableClass()
|
void |
addReader(Class<?> c,
JsonReader.JsonClassReader reader)
Deprecated.
use ReadOptionsBuilder.withCustomReader() to create any additional readers you'll need.
|
static void |
assignInstantiator(Class<?> c,
JsonReader.ClassFactory factory)
Deprecated.
|
static void |
assignInstantiator(String className,
JsonReader.ClassFactory factory)
Deprecated.
|
void |
close() |
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.
|
ClassLoader |
getClassLoader() |
protected FastReader |
getReader(InputStream inputStream) |
Object |
jsonObjectsToJava(JsonObject root)
Deprecated.
|
static <T> T |
jsonToJava(InputStream inputStream,
Map<String,Object> optionalArgs)
Deprecated.
|
static <T> T |
jsonToJava(InputStream inputStream,
Map<String,Object> optionalArgs,
int maxDepth)
Deprecated.
|
static <T> T |
jsonToJava(String json)
Deprecated.
|
static <T> T |
jsonToJava(String json,
Map<String,Object> optionalArgs)
Deprecated.
|
static Object |
jsonToJava(String json,
Map<String,Object> optionalArgs,
int maxDepth)
Deprecated.
|
static Map |
jsonToMaps(InputStream inputStream,
Map<String,Object> optionalArgs)
Deprecated.
|
static Map |
jsonToMaps(InputStream inputStream,
Map<String,Object> optionalArgs,
int maxDepth)
Deprecated.
|
static Map |
jsonToMaps(String json)
Deprecated.
|
static Map |
jsonToMaps(String json,
int maxDepth)
Deprecated.
|
static Map |
jsonToMaps(String json,
Map<String,Object> optionalArgs)
Deprecated.
|
static Map |
jsonToMaps(String json,
Map<String,Object> optionalArgs,
int maxDepth)
Deprecated.
|
Object |
readObject()
Read JSON input from the stream that was set up in the constructor, turning it into
Java Maps (JsonObject's).
|
<T> T |
reentrantConvertParsedMapsToJava(JsonObject root,
Class<T> hint)
This method converts a root Map, (which contains nested Maps
and so forth representing a Java Object graph), to a Java
object instance.
|
static <T> T |
toMaps(InputStream inputStream,
ReadOptions readOptions)
Note that the return type will match one of these JSON types (array, Map, string, long, boolean, or null).
|
static <T> T |
toMaps(String json)
Note that the return type will match one of these JSON types (array, Map, string, long, boolean, or null).
|
static <T> T |
toMaps(String json,
ReadOptions readOptions)
Note that the return type will match one of these JSON types (array, Map, string, long, boolean, or null).
|
static <T> T |
toObjects(byte[] bytes,
ReadOptions options)
Convert the passed in JSON string into a Java object graph.
|
static <T> T |
toObjects(InputStream input,
ReadOptions options)
Convert the passed in JSON string into a Java object graph.
|
static <T> T |
toObjects(String json)
Convert the passed in JSON string into a Java object graph.
|
static <T> T |
toObjects(String jsonString,
ReadOptions options)
Convert the passed in JSON string into a Java object graph.
|
protected boolean |
useMaps() |
public static final String CUSTOM_READER_MAP
public static final String NOT_CUSTOM_READER_MAP
public static final String USE_MAPS
public static final String UNKNOWN_OBJECT
public static final String FAIL_ON_UNKNOWN_TYPE
public static final String JSON_READER
public static final String OBJECT_RESOLVER
public static final String TYPE_NAME_MAP
public static final String MISSING_FIELD_HANDLER
public static final String CLASSLOADER
public static final String FACTORIES
@Deprecated public JsonReader(int maxDepth)
maxDepth
- - maximum recursion depth@Deprecated public JsonReader()
@Deprecated public JsonReader(InputStream inputStream, int maxDepth)
inputStream
- - input stream to supply jsonmaxDepth
- - maximum recursion depth@Deprecated public JsonReader(InputStream inputStream)
inputStream
- input stream@Deprecated public JsonReader(Map<String,Object> optionalArgs, int maxDepth)
optionalArgs
- Map of optional arguments for the JsonReader.maxDepth
- Maximum parsing depth.@Deprecated public JsonReader(Map<String,Object> optionalArgs)
optionalArgs
- Map of optional arguments for the JsonReader.@Deprecated public JsonReader(InputStream inputStream, boolean useMaps, int maxDepth)
inputStream
- - json StringuseMaps
- - return data in map of mapsmaxDepth
- - maximum recursion depth@Deprecated public JsonReader(InputStream inputStream, boolean useMaps)
inputStream
- - json StringuseMaps
- - return data in map of maps@Deprecated public JsonReader(InputStream inputStream, Map<String,Object> optionalArgs, int maxDepth)
inputStream
- - json StringoptionalArgs
- - old way of passing reader argumentsmaxDepth
- - max recursion depth@Deprecated public JsonReader(InputStream inputStream, Map<String,Object> optionalArgs)
inputStream
- - json StringoptionalArgs
- - old way of passing reader arguments@Deprecated public JsonReader(String json, Map<String,Object> optionalArgs, int maxDepth)
json
- - json StringoptionalArgs
- - old way of passing reader argumentsmaxDepth
- - max recursion depth@Deprecated public JsonReader(String json, Map<String,Object> optionalArgs)
json
- - json StringoptionalArgs
- - old way of passing reader arguments@Deprecated public JsonReader(byte[] inp, Map<String,Object> optionalArgs, int maxDepth)
inp
- - byte array with json data in it.optionalArgs
- - deprecated options.maxDepth
- - max recursion depth@Deprecated public JsonReader(byte[] inp, Map<String,Object> optionalArgs)
inp
- - byte array with json data in it.optionalArgs
- - deprecated options.public JsonReader(String json)
json
- - json Stringpublic JsonReader(String json, ReadOptions readOptions)
json
- json StringreadOptions
- Read Optionspublic JsonReader(byte[] bytes, ReadOptions readOptions)
bytes
- utf-8 encoded bytesreadOptions
- Read Optionspublic JsonReader(InputStream inp, ReadOptions readOptions)
inp
- InputStream of utf-encoded jsonreadOptions
- Read Optionspublic JsonReader(InputStream input, ReadOptions readOptions, ReferenceTracker references)
public JsonReader(ReadOptions options)
options
- - read options@Deprecated public static void assignInstantiator(String className, JsonReader.ClassFactory factory)
className
- Class name to assign an ClassFactory tofactory
- ClassFactory that will create 'c' instances@Deprecated public static void assignInstantiator(Class<?> c, JsonReader.ClassFactory factory)
c
- Class to assign on ClassFActoryfactory
- ClassFactory that wil create instance of that class.@Deprecated public void addReader(Class<?> c, JsonReader.JsonClassReader reader)
c
- Class to assign a custom JSON reader toreader
- The JsonClassReader which will read the custom JSON format of 'c'@Deprecated public void addNotCustomReader(Class<?> c)
c
- Class to which to force no custom JSON reading to occur.public static <T> T toObjects(InputStream input, ReadOptions options)
input
- Input stream of UTF-8 json string dataoptions
- Read optionspublic static <T> T toObjects(byte[] bytes, ReadOptions options)
bytes
- UTF-8 byte arrayoptions
- Read optionspublic static <T> T toObjects(String jsonString, ReadOptions options)
jsonString
- String JSON inputoptions
- Read optionspublic static <T> T toObjects(String json)
json
- String JSON input@Deprecated public static <T> T jsonToJava(String json)
json
- String JSON input@Deprecated public static Object jsonToJava(String json, Map<String,Object> optionalArgs, int maxDepth)
json
- String JSON inputoptionalArgs
- Map of optional parameters to control parsing. See readme file for details.maxDepth
- Maximum parsing depth.@Deprecated public static <T> T jsonToJava(String json, Map<String,Object> optionalArgs)
json
- String JSON inputoptionalArgs
- Map of optional parameters to control parsing. See readme file for details.@Deprecated public static <T> T jsonToJava(InputStream inputStream, Map<String,Object> optionalArgs, int maxDepth)
inputStream
- InputStream containing JSON inputoptionalArgs
- Map of optional parameters to control parsing. See readme file for details.maxDepth
- Maximum parsing depth.@Deprecated public static <T> T jsonToJava(InputStream inputStream, Map<String,Object> optionalArgs)
inputStream
- InputStream containing JSON inputoptionalArgs
- Map of optional parameters to control parsing. See readme file for details.@Deprecated public static Map jsonToMaps(String json, int maxDepth)
json
- String of JSON contentmaxDepth
- Maximum parsing depth.@Deprecated public static Map jsonToMaps(String json)
json
- String of JSON content@Deprecated public static Map jsonToMaps(String json, Map<String,Object> optionalArgs, int maxDepth)
json
- String of JSON contentoptionalArgs
- Map of optional arguments to control customization. See readme file for
details on these options.maxDepth
- Maximum parsing depth.@Deprecated public static Map jsonToMaps(String json, Map<String,Object> optionalArgs)
json
- String of JSON contentoptionalArgs
- Map of optional arguments to control customization. See readme file for
details on these options.@Deprecated public static Map jsonToMaps(InputStream inputStream, Map<String,Object> optionalArgs, int maxDepth)
inputStream
- containing JSON contentoptionalArgs
- Map of optional arguments to control customization. See readme file for
details on these options.maxDepth
- Maximum parsing depth.@Deprecated public static Map jsonToMaps(InputStream inputStream, Map<String,Object> optionalArgs)
inputStream
- containing JSON contentoptionalArgs
- Map of optional arguments to control customization. See readme file for
details on these options.public static <T> T toMaps(String json)
json
- json stringpublic static <T> T toMaps(String json, ReadOptions readOptions)
json
- json stringreadOptions
- options to use when readingpublic static <T> T toMaps(InputStream inputStream, ReadOptions readOptions)
inputStream
- bytes representing UTF-8 stringreadOptions
- options to use when readingprotected FastReader getReader(InputStream inputStream)
public Object readObject()
@Deprecated public Object jsonObjectsToJava(JsonObject root)
root
- JsonObject instance that was the root object from the
JSON input that was parsed in an earlier call to JsonReader.protected boolean useMaps()
public ClassLoader getClassLoader()
public <T> T reentrantConvertParsedMapsToJava(JsonObject root, Class<T> hint)
root
- JsonObject instance that was the root object from thehint
- When you know the type you will be returning.
JSON input that was parsed in an earlier call to JsonReader.protected Object convertParsedMapsToJava(JsonObject root)
root
- JsonObject instance that was the root object from the
JSON input that was parsed in an earlier call to JsonReader.public void close()
close
in interface Closeable
close
in interface AutoCloseable
Copyright © 2023. All rights reserved.