public class MapResolver extends Object
The MapResolver converts the raw Maps created from the JsonParser to higher
quality Maps representing the implied object graph. It does this by replacing
@ref
values with the Map indicated by the @id key with the same value.
This approach 'wires' 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.Missingfields
stores missing fields information to notify client after the complete deserialization resolution
|
Modifier and Type | Field and Description |
---|---|
protected Collection<Resolver.Missingfields> |
missingFields |
protected JsonReader |
reader |
Modifier | Constructor and Description |
---|---|
protected |
MapResolver(JsonReader reader) |
Modifier and Type | Method and Description |
---|---|
protected void |
cleanup() |
protected Object |
coerceCertainTypes(String type) |
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<String,Object> 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 EnumSet<?> |
extractEnumSet(Class c,
JsonObject<String,Object> jsonObj) |
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,
JsonObject jsonObject) |
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 Object |
readIfMatching(Object o,
Class<?> compType,
Deque<JsonObject<String,Object>> stack) |
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.
|
void |
traverseFields(Deque<JsonObject<String,Object>> stack,
JsonObject<String,Object> jsonObj)
Walk the JsonObject fields and perform necessary substitutions so that all references matched up.
|
protected void |
traverseMap(Deque<JsonObject<String,Object>> stack,
JsonObject<String,Object> jsonObj)
Process java.util.Map and it's derivatives.
|
protected final JsonReader reader
protected final Collection<Resolver.Missingfields> missingFields
protected MapResolver(JsonReader reader)
protected Object readIfMatching(Object o, Class<?> compType, Deque<JsonObject<String,Object>> stack)
public void traverseFields(Deque<JsonObject<String,Object>> stack, JsonObject<String,Object> jsonObj)
stack
- Stack (Deque) used for graph traversal.jsonObj
- a Map-of-Map representation of the current object being examined (containing all fields).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<String,Object> 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 EnumSet<?> extractEnumSet(Class c, JsonObject<String,Object> jsonObj)
protected void patchUnresolvedReferences()
protected void rehashMaps()
public static Object newInstance(Class c, JsonObject jsonObject)
protected Map<Class,JsonReader.JsonClassReaderBase> getReaders()
protected boolean notCustom(Class cls)
Copyright © 2024. All rights reserved.