Class Resolver
- Direct Known Subclasses:
MapResolver
,ObjectResolver
The subclasses that override this class can build an object graph using Java classes or a Map-of-Map representation. In both cases, the @ref value will be replaced with the Object (or Map) that had the corresponding @id.
- Author:
- John DeRegnaucourt ([email protected])
Copyright (c) Cedar Software LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
License
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
stores missing fields information to notify client after the complete deserialization resolution -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Resolver
(ReadOptions readOptions, ReferenceTracker references, com.cedarsoftware.util.convert.Converter converter) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
cleanup()
com.cedarsoftware.util.convert.Converter
void
push
(JsonObject jsonObject) Push a JsonObject on the work stack that has not yet had it's fields move over to it's Java peer (.target)protected abstract Object
readWithFactoryIfExists
(Object o, Type compType) protected abstract Object
resolveArray
(Type suggestedType, List<Object> list) protected void
setArrayElement
(Object array, int index, Object element) <T> T
toJavaObjects
(JsonObject rootObj, Type rootType) Convert a Parsed JsonObject to a Fully Resolved Java Objectprotected abstract void
traverseArray
(JsonObject jsonObj) protected abstract void
traverseCollection
(JsonObject jsonObj) abstract void
traverseFields
(JsonObject jsonObj) <T> T
traverseJsonObject
(JsonObject root) Walk a JsonObject (Map of String keys to values) and return the Java object equivalent filled in as good as possible (everything except unresolved reference fields or unresolved array/collection elements).protected void
traverseMap
(JsonObject jsonObj) Process java.util.Map and it's derivatives.protected void
traverseObject
(JsonObject jsonObj) protected void
traverseSpecificType
(JsonObject jsonObj) boolean
valueToTarget
(JsonObject jsonObject)
-
Field Details
-
stack
-
-
Constructor Details
-
Resolver
protected Resolver(ReadOptions readOptions, ReferenceTracker references, com.cedarsoftware.util.convert.Converter converter)
-
-
Method Details
-
getReadOptions
-
getReferences
-
getConverter
public com.cedarsoftware.util.convert.Converter getConverter() -
toJavaObjects
Convert a Parsed JsonObject to a Fully Resolved Java Object
This method converts a root-level
JsonObject
—a Map-of-Maps representation of parsed JSON—into an actual Java object instance. TheJsonObject
is typically produced by a prior call toJsonIo.toObjects(String)
orJsonIo.toObjects(InputStream)
when using theReadOptions.returnAsJsonObjects()
setting. The conversion process uses the providedroot
parameter, aType
that represents the expected root type (including any generic type parameters). Although the full type information is preserved for resolution, theJsonObject
's legacyhintType
field (which remains aClass<?>
) is set using the raw class extracted from the provided type.The resolution process works as follows:
-
Reference Resolution: If the
JsonObject
is a reference, it is resolved using the internal reference map. If a referenced object is found, it is returned immediately. -
Already Converted Check: If the
JsonObject
has already been fully converted (i.e. itsisFinished
flag is set), then its target (the converted Java object) is returned. -
Instance Creation and Traversal: Otherwise, the method sets the hint type on the
JsonObject
(using the raw class extracted from the provided fullType
), creates a new instance (if necessary), and then traverses the object graph to resolve nested references and perform conversions.
Parameters
-
rootObj - The root
JsonObject
(a Map-of-Maps) representing the parsed JSON data. -
root - A
Type
representing the expected Java type (including full generic details) for the resulting object. Ifnull
, type inference defaults to a genericMap
representation.
Return Value
Returns a Java object that represents the fully resolved version of the JSON data. Depending on the JSON structure and the provided type hint, the result may be a user-defined DTO, a collection, an array, or a primitive value.
- Type Parameters:
T
- the type of the resulting Java object.- Parameters:
rootObj
- the rootJsonObject
representing parsed JSON data.rootType
- aType
representing the expected Java type (with full generic details) for the root object; may benull
.- Returns:
- a fully resolved Java object representing the JSON data.
-
Reference Resolution: If the
-
traverseJsonObject
Walk a JsonObject (Map of String keys to values) and return the Java object equivalent filled in as good as possible (everything except unresolved reference fields or unresolved array/collection elements).- Parameters:
root
- JsonObject reference to a Map-of-Maps representation of the JSON input after it has been completely read.- Returns:
- Properly constructed, typed, Java object graph built from a Map of Maps representation (JsonObject root).
-
traverseSpecificType
-
traverseObject
-
getSealedSupplier
-
push
Push a JsonObject on the work stack that has not yet had it's fields move over to it's Java peer (.target)- Parameters:
jsonObject
- JsonObject that supplies the source values for the Java peer (target)
-
traverseFields
-
readWithFactoryIfExists
-
traverseCollection
-
traverseArray
-
cleanup
protected void cleanup() -
traverseMap
Process java.util.Map and it's derivatives. These are written specially so that the serialization does not expose the class internals (internal fields of TreeMap for example).- Parameters:
jsonObj
- a Map-of-Map representation of the JSON input stream.
-
valueToTarget
-
setArrayElement
-
resolveArray
-