Class ReadOptionsBuilder

java.lang.Object
com.cedarsoftware.util.io.ReadOptionsBuilder

public class ReadOptionsBuilder extends Object
Author:
Kenny Partlow ([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

http://www.apache.org/licenses/LICENSE-2.0

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.*
  • Constructor Details

    • ReadOptionsBuilder

      public ReadOptionsBuilder()
  • Method Details

    • addPermanentCoercedType

      public static void addPermanentCoercedType(String fqName, Class<?> c)
      Call this method to add a permanent (JVM lifetime) coercion of one class to another for creatint into an object. Examples of classes that might need this are proxied classes such as HibernateBags, etc. That you want to create as regular jvm collections.
      Parameters:
      fqName - Class to assign a custom JSON reader to
      c - The JsonClassReader which will read the custom JSON format of 'c'
    • addReaderPermanent

      public static void addReaderPermanent(Class c, JsonReader.JsonClassReader reader)
      Call this method to add a custom JSON reader to json-io. It will associate the Class 'c' to the reader you pass in. The readers are found with isAssignableFrom(). If this is too broad, causing too many classes to be associated to the custom reader, you can indicate that json-io should not use a custom reader for a particular class, by calling the addNotCustomReader() method. This method will add the customer reader such that it will be there permanently, for the life of the JVM (static).
      Parameters:
      c - Class to assign a custom JSON reader to
      reader - The JsonClassReader which will read the custom JSON format of 'c'
    • assignInstantiator

      public static void assignInstantiator(String className, JsonReader.ClassFactory factory)
      For difficult to instantiate classes, you can add your own ClassFactory which will be called when the passed in class 'c' is encountered. Your ClassFactory will be called with newInstance(class, Object) and your factory is expected to return a new instance of 'c' and can use values from Object (JsonMap or simple value) to initialize the created class with the appropriate values.

      This API is an 'escape hatch' to allow ANY object to be instantiated by JsonReader and is useful when you encounter a class that JsonReader cannot instantiate using its internal exhausting attempts (trying all constructors, varying arguments to them, etc.)

      Parameters:
      className - Class name to assign an ClassFactory to
      factory - ClassFactory that will create 'c' instances
    • assignInstantiator

      public static void assignInstantiator(Class c, JsonReader.ClassFactory factory)
      See comment on method JsonReader.assignInstantiator(String, ClassFactory)
    • setUnknownTypeClass

      public ReadOptionsBuilder setUnknownTypeClass(Class<?> c)
    • setMissingFieldHandler

      public ReadOptionsBuilder setMissingFieldHandler(JsonReader.MissingFieldHandler missingFieldHandler)
    • failOnUnknownType

      public ReadOptionsBuilder failOnUnknownType()
    • withClassLoader

      public ReadOptionsBuilder withClassLoader(ClassLoader classLoader)
    • returnAsMaps

      public ReadOptionsBuilder returnAsMaps()
    • withCoercedType

      public ReadOptionsBuilder withCoercedType(Class<?> oldType, Class<?> newType)
    • withCoercedType

      public ReadOptionsBuilder withCoercedType(String fullyQualifedNameOldType, Class<?> newType)
    • withCustomTypeName

      public ReadOptionsBuilder withCustomTypeName(Class<?> type, String newTypeName)
    • withCustomTypeName

      public ReadOptionsBuilder withCustomTypeName(String type, String newTypeName)
    • withCustomTypeNames

      public ReadOptionsBuilder withCustomTypeNames(Map<String,String> map)
    • withCustomReader

      public ReadOptionsBuilder withCustomReader(Class<?> c, JsonReader.JsonClassReader reader)
      Call this method to add a custom JSON reader to json-io. It will associate the Class 'c' to the reader you pass in. The readers are found with isAssignableFrom(). If this is too broad, causing too many classes to be associated to the custom reader, you can indicate that json-io should not use a custom reader for a particular class, by calling the addNotCustomReader() method.
      Parameters:
      c - Class to assign a custom JSON reader to
      reader - The JsonClassReader which will read the custom JSON format of 'c'
    • withCustomReaders

      public ReadOptionsBuilder withCustomReaders(Map<? extends Class<?>,? extends JsonReader.JsonClassReader> map)
      This call will add all entries from the current map into the readers map.
      Parameters:
      map - This map contains classes mapped to their respctive readers
    • withNonCustomizableClass

      public ReadOptionsBuilder withNonCustomizableClass(Class<?> c)
    • withMaxDepth

      public ReadOptionsBuilder withMaxDepth(int maxDepth)
    • withNonCustomizableClasses

      public ReadOptionsBuilder withNonCustomizableClasses(Collection<Class<?>> collection)
    • withClassFactory

      public ReadOptionsBuilder withClassFactory(Class<?> type, JsonReader.ClassFactory factory)
    • withClassFactories

      public ReadOptionsBuilder withClassFactories(Map<Class<?>,? extends JsonReader.ClassFactory> factories)
    • fromMap

      public static ReadOptionsBuilder fromMap(Map<String,Object> args)
    • build

      public ReadOptions build()