Package com.cedarsoftware.io
Class Resolver
java.lang.Object
com.cedarsoftware.io.Resolver
- Direct Known Subclasses:
MapResolver
,ObjectResolver
This class is used to convert a source of Java Maps that were created from
the JsonParser. These are in 'raw' form with no 'pointers'. This code will
reconstruct the 'shape' of the graph by connecting @ref's to @ids.
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 TypeMethodDescriptionabstract void
assignField
(JsonObject jsonObj, Injector injector, Object rhs) protected void
cleanup()
com.cedarsoftware.util.convert.Converter
boolean
isConvertable
(Class<?> type) 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, Class<?> compType) <T> T
toJavaObjects
(JsonObject rootObj, Class<T> root) This method converts a rootObj Map, (which contains nested Maps and so forth representing a Java Object graph), to a Java object instance.protected 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.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
This method converts a rootObj Map, (which contains nested Maps and so forth representing a Java Object graph), to a Java object instance. The rootObj map came from using the JsonReader to parse a JSON graph (using the API that puts the graph into Maps, not the typed representation).- Parameters:
rootObj
- JsonObject instance that was the rootObj object from theroot
- When you know the type you will be returning. Can be null (effectively Map.class) JSON input that was parsed in an earlier call to JsonReader.- Returns:
- a typed Java instance that was serialized into JSON.
-
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
-
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
-
assignField
-
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
-
isConvertable
-