Package com.cedarsoftware.util.io
Class ReadOptionsBuilder
java.lang.Object
com.cedarsoftware.util.io.ReadOptionsBuilder
- 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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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.static void
addReaderPermanent
(Class c, JsonReader.JsonClassReader reader) Call this method to add a custom JSON reader to json-io.static void
assignInstantiator
(Class c, JsonReader.ClassFactory factory) See comment on method JsonReader.assignInstantiator(String, ClassFactory)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.build()
static ReadOptionsBuilder
setMissingFieldHandler
(JsonReader.MissingFieldHandler missingFieldHandler) setUnknownTypeClass
(Class<?> c) withClassFactories
(Map<Class<?>, ? extends JsonReader.ClassFactory> factories) withClassFactory
(Class<?> type, JsonReader.ClassFactory factory) withClassLoader
(ClassLoader classLoader) withCoercedType
(Class<?> oldType, Class<?> newType) withCoercedType
(String fullyQualifedNameOldType, Class<?> newType) withCustomReader
(Class<?> c, JsonReader.JsonClassReader reader) Call this method to add a custom JSON reader to json-io.withCustomReaders
(Map<? extends Class<?>, ? extends JsonReader.JsonClassReader> map) This call will add all entries from the current map into the readers map.withCustomTypeName
(Class<?> type, String newTypeName) withCustomTypeName
(String type, String newTypeName) withCustomTypeNames
(Map<String, String> map) withMaxDepth
(int maxDepth) withNonCustomizableClasses
(Collection<Class<?>> collection)
-
Constructor Details
-
ReadOptionsBuilder
public ReadOptionsBuilder()
-
-
Method Details
-
addPermanentCoercedType
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 toc
- The JsonClassReader which will read the custom JSON format of 'c'
-
addReaderPermanent
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 toreader
- The JsonClassReader which will read the custom JSON format of 'c'
-
assignInstantiator
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 tofactory
- ClassFactory that will create 'c' instances
-
assignInstantiator
See comment on method JsonReader.assignInstantiator(String, ClassFactory) -
setUnknownTypeClass
-
setMissingFieldHandler
public ReadOptionsBuilder setMissingFieldHandler(JsonReader.MissingFieldHandler missingFieldHandler) -
failOnUnknownType
-
withClassLoader
-
returnAsMaps
-
withCoercedType
-
withCoercedType
-
withCustomTypeName
-
withCustomTypeName
-
withCustomTypeNames
-
withCustomReader
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 toreader
- 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
-
withMaxDepth
-
withNonCustomizableClasses
-
withClassFactory
-
withClassFactories
public ReadOptionsBuilder withClassFactories(Map<Class<?>, ? extends JsonReader.ClassFactory> factories) -
fromMap
-
build
-