Class Resolver

java.lang.Object
com.cedarsoftware.io.Resolver
Direct Known Subclasses:
MapResolver, ObjectResolver

public abstract class Resolver extends Object
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.
  • Field Details

  • Constructor Details

    • Resolver

      protected Resolver(ReadOptions readOptions, ReferenceTracker references, com.cedarsoftware.util.convert.Converter converter)
  • Method Details

    • getReadOptions

      public ReadOptions getReadOptions()
    • getReferences

      public ReferenceTracker getReferences()
    • getConverter

      public com.cedarsoftware.util.convert.Converter getConverter()
    • toJavaObjects

      public <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. 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 the
      root - 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

      public <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).
      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

      public void traverseSpecificType(JsonObject jsonObj)
    • getSealedSupplier

      public SealedSupplier getSealedSupplier()
    • push

      public 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)
      Parameters:
      jsonObject - JsonObject that supplies the source values for the Java peer (target)
    • traverseFields

      public abstract void traverseFields(JsonObject jsonObj)
    • readWithFactoryIfExists

      protected abstract Object readWithFactoryIfExists(Object o, Class<?> compType)
    • traverseCollection

      protected abstract void traverseCollection(JsonObject jsonObj)
    • traverseArray

      protected abstract void traverseArray(JsonObject jsonObj)
    • assignField

      public abstract void assignField(JsonObject jsonObj, Injector injector, Object rhs)
    • cleanup

      protected void cleanup()
    • traverseMap

      protected void traverseMap(JsonObject jsonObj)
      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

      public boolean valueToTarget(JsonObject jsonObject)
    • isConvertable

      public boolean isConvertable(Class<?> type)