public class MapResolver extends Object
@ref
values with the Map with an @id key with the same value.
This approach 'rewires' the original object graph. During the resolution process,
if 'peer' classes can be found for given Maps (for example, an @type entry is
available which indicates the class that would have been associated to the Map,
then the associated class is consulted to help 'improve' the quality of the primitive
values within the map fields. For example, if the peer class indicated that a field
was of type 'short', and the Map had a long value (JSON only returns long's for integer
types), then the long would be converted to a short.
The final Map representation is a very high-quality graph that represents the original
JSON graph. It can be passed as input to JsonWriter, and the JsonWriter will write
out the equivalent JSON to what was originally read. This technique allows json-io to
be used on a machine that does not have any of the Java classes from the original graph,
read it in a JSON graph (any JSON graph), return the equivalent maps, allow mutations of
those maps, and finally this graph can be written out.Modifier and Type | Class and Description |
---|---|
protected static class |
Resolver.UnresolvedReference
UnresolvedReference is created to hold a logical pointer to a reference that
could not yet be loaded, as the @ref appears ahead of the referenced object's
definition.
|
Modifier and Type | Field and Description |
---|---|
protected JsonReader |
reader |
protected Collection<Resolver.UnresolvedReference> |
unresolvedRefs |
Modifier | Constructor and Description |
---|---|
protected |
MapResolver(JsonReader reader) |
Modifier and Type | Method and Description |
---|---|
protected void |
cleanup() |
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 static void |
convertMapToKeysItems(JsonObject map)
Convert an input JsonObject map (known to represent a Map.class or derivative) that has regular keys and values
to have its keys placed into @keys, and its values placed into @items.
|
protected Object |
createJavaObjectInstance(Class clazz,
JsonObject jsonObj)
This method creates a Java Object instance based on the passed in parameters.
|
protected JsonReader.JsonClassReaderBase |
getCustomReader(Class c) |
protected JsonReader |
getReader() |
protected Map<Class,JsonReader.JsonClassReaderBase> |
getReaders() |
protected JsonObject |
getReferencedObj(Long ref) |
static Object |
newInstance(Class c) |
protected boolean |
notCustom(Class cls) |
protected void |
patchUnresolvedReferences()
For all fields where the value was "@ref":"n" where 'n' was the id of an object
that had not yet been encountered in the stream, make the final substitution.
|
protected void |
rehashMaps()
Process Maps/Sets (fix up their internal indexing structure)
This is required because Maps hash items using hashCode(), which will
change between VMs.
|
protected void |
traverseArray(Deque<JsonObject<String,Object>> stack,
JsonObject<String,Object> jsonObj) |
protected void |
traverseCollection(Deque<JsonObject<String,Object>> stack,
JsonObject<String,Object> jsonObj)
Process java.util.Collection and it's derivatives.
|
protected void |
traverseFields(Deque<JsonObject<String,Object>> stack,
JsonObject<String,Object> jsonObj) |
protected void |
traverseMap(Deque<JsonObject<String,Object>> stack,
JsonObject<String,Object> jsonObj)
Process java.util.Map and it's derivatives.
|
protected final Collection<Resolver.UnresolvedReference> unresolvedRefs
protected final JsonReader reader
protected MapResolver(JsonReader reader)
protected void traverseFields(Deque<JsonObject<String,Object>> stack, JsonObject<String,Object> jsonObj)
protected void traverseCollection(Deque<JsonObject<String,Object>> stack, JsonObject<String,Object> jsonObj)
stack
- a Stack (Deque) used to support graph traversal.jsonObj
- a Map-of-Map representation of the JSON input stream.protected void traverseArray(Deque<JsonObject<String,Object>> stack, JsonObject<String,Object> jsonObj)
protected JsonReader getReader()
protected Object convertMapsToObjects(JsonObject<String,Object> root)
root
- JsonObject reference to a Map-of-Maps representation of the JSON
input after it has been completely read.protected void cleanup()
protected void traverseMap(Deque<JsonObject<String,Object>> stack, JsonObject<String,Object> jsonObj)
stack
- a Stack (Deque) used to support graph traversal.jsonObj
- a Map-of-Map representation of the JSON input stream.protected static void convertMapToKeysItems(JsonObject map)
map
- Map to convertprotected Object createJavaObjectInstance(Class clazz, JsonObject jsonObj)
clazz
- Instance will be create of this class.jsonObj
- Map-of-Map representation of object to create.protected JsonObject getReferencedObj(Long ref)
protected JsonReader.JsonClassReaderBase getCustomReader(Class c)
protected void patchUnresolvedReferences()
protected void rehashMaps()
protected Map<Class,JsonReader.JsonClassReaderBase> getReaders()
protected boolean notCustom(Class cls)
Copyright © 2015. All rights reserved.