public class MapResolver extends Resolver
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.
Resolver.Missingfields
missingFields
Modifier | Constructor and Description |
---|---|
protected |
MapResolver(ReadOptions readOptions,
ReferenceTracker references,
com.cedarsoftware.util.convert.Converter converter) |
Modifier and Type | Method and Description |
---|---|
protected Object |
readWithFactoryIfExists(Object o,
Class compType,
Deque<JsonObject> stack) |
protected void |
traverseArray(Deque<JsonObject> stack,
JsonObject jsonObj) |
protected void |
traverseCollection(Deque<JsonObject> stack,
JsonObject jsonObj)
Process java.util.Collection and it's derivatives.
|
void |
traverseFields(Deque<JsonObject> stack,
JsonObject jsonObj)
Walk the JsonObject fields and perform necessary substitutions so that all references matched up.
|
cleanup, coerceClassIfNeeded, convertJsonValuesToJava, convertMapToKeysItems, createInstance, createInstanceUsingType, extractEnumSet, patchUnresolvedReferences, reentrantConvertJsonValueToJava, rehashMaps, resolveRefs, traverseMap
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getConverter, getReadOptions, getReferences
protected MapResolver(ReadOptions readOptions, ReferenceTracker references, com.cedarsoftware.util.convert.Converter converter)
protected Object readWithFactoryIfExists(Object o, Class compType, Deque<JsonObject> stack)
readWithFactoryIfExists
in class Resolver
public void traverseFields(Deque<JsonObject> stack, JsonObject 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> stack, JsonObject jsonObj)
traverseCollection
in class Resolver
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> stack, JsonObject jsonObj)
traverseArray
in class Resolver
Copyright © 2024. All rights reserved.