public class ObjectResolver extends Resolver
The ObjectResolver converts the raw Maps created from the JsonParser to Java objects (a graph of Java instances). The Maps have an optional type entry associated to them to indicate what Java peer instance to create. The reason type is optional is because it can be inferred in a couple instances. A non-primitive field that points to an object that is of the same type of the field, does not require the '@type' because it can be inferred from the field. This is not always the case. For example, if a Person field points to an Employee object (where Employee is a subclass of Person), then the resolver cannot create an instance of the field type (Person) because this is not the proper type. (It had an Employee record with more fields in this example). In this case, the writer recognizes that the instance type and field type are not the same and therefore it writes the @type.
A similar case as above occurs with specific array types. If there is a Person[] containing Person and Employee instances, then the Person instances will not have the '@type' but the employee instances will (because they are more derived than Person).
The resolver 'wires' the original object graph. It does this by replacing '@ref' values in the Maps with pointers (on the field of the associated instance of the Map) to the object that has the same ID. If the object has not yet been read, then an UnresolvedReference is created. These are back-patched at the end of the resolution process. UnresolvedReference keeps track of what field or array element the actual value should be stored within, and then locates the object (by id), and updates the appropriate value.
Resolver.Missingfields
missingFields
Modifier | Constructor and Description |
---|---|
protected |
ObjectResolver(ReadOptions readOptions,
ReferenceTracker references,
com.cedarsoftware.util.convert.Converter converter)
Constructor
|
Modifier and Type | Method and Description |
---|---|
protected void |
assignField(Deque<JsonObject> stack,
JsonObject jsonObj,
Injector injector,
Object rhs)
Map Json Map object field to Java object field.
|
static Class |
getRawType(Type t)
Given the passed in Type t, return the raw type of it, if the passed in value is a ParameterizedType.
|
protected void |
handleMissingField(Deque<JsonObject> stack,
JsonObject jsonObj,
Object rhs,
String missingField)
Try to create a java object from the missing field.
|
protected Object |
readWithFactoryIfExists(Object o,
Class inferredType,
Deque<JsonObject> stack)
Convert the passed in object (o) to a proper Java object.
|
static void |
reconcileCollection(JsonObject jsonObj,
Collection col) |
protected void |
traverseArray(Deque<JsonObject> stack,
JsonObject jsonObj)
Traverse the JsonObject associated to an array (of any type).
|
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 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.
|
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 ObjectResolver(ReadOptions readOptions, ReferenceTracker references, com.cedarsoftware.util.convert.Converter converter)
readOptions
- Options to use while reading.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 assignField(Deque<JsonObject> stack, JsonObject jsonObj, Injector injector, Object rhs)
stack
- Stack (Deque) used for graph traversal.jsonObj
- a Map-of-Map representation of the current object being examined (containing all fields).injector
- instance of injector used for setting values on the object.rhs
- the JSON value that will be converted and stored in the 'field' on the associated
Java target object.protected void handleMissingField(Deque<JsonObject> stack, JsonObject jsonObj, Object rhs, String missingField)
stack
- Stack (Deque) used for graph traversal.jsonObj
- a Map-of-Map representation of the current object being examined (containing all fields).rhs
- the JSON value that will be converted and stored in the 'field' on the associated Java target object.missingField
- name of the missing field in the java object.protected void traverseCollection(Deque<JsonObject> stack, JsonObject jsonObj)
traverseCollection
in class Resolver
jsonObj
- a Map-of-Map representation of the JSON input stream.public static void reconcileCollection(JsonObject jsonObj, Collection col)
protected void traverseArray(Deque<JsonObject> stack, JsonObject jsonObj)
traverseArray
in class Resolver
stack
- a Stack (Deque) used to support graph traversal.jsonObj
- a Map-of-Map representation of the JSON input stream.protected Object readWithFactoryIfExists(Object o, Class inferredType, Deque<JsonObject> stack)
readWithFactoryIfExists
in class Resolver
o
- Object to read (convert). Will be either a JsonObject or a JSON primitive String, long, boolean,
double, or null.inferredType
- Class destination type to which the passed in object should be converted to.stack
- a Stack (Deque) used to support graph traversal.public static Class getRawType(Type t)
t
- Type to attempt to get raw type from.Copyright © 2024. All rights reserved.