public class ReadOptionsBuilder extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ReadOptionsBuilder.DefaultConverterOptions |
static class |
ReadOptionsBuilder.DefaultReadOptions |
Constructor and Description |
---|
ReadOptionsBuilder()
Start with default options
|
Modifier and Type | Method and Description |
---|---|
ReadOptionsBuilder |
addClassFactory(Class<?> clazz,
JsonReader.ClassFactory factory)
Associate a ClassFactory to a Class that needs help being constructed and read in.
|
ReadOptionsBuilder |
addConverterOverride(Class<?> source,
Class<?> target,
com.cedarsoftware.util.convert.Convert<?> conversionFunction) |
ReadOptionsBuilder |
addCustomOption(String key,
Object value)
Add a custom option, which may be useful when writing custom readers.
|
ReadOptionsBuilder |
addCustomReaderClass(Class<?> clazz,
JsonReader.JsonClassReader customReader) |
ReadOptionsBuilder |
addNonReferenceableClass(Class<?> clazz) |
ReadOptionsBuilder |
addNotCustomReaderClass(Class<?> notCustomClass)
Add a class to the not-customized list - the list of classes that you do not want to be picked up by a
custom reader (that could happen through inheritance).
|
static void |
addPermanentAlias(Class<?> sourceClass,
String alias)
Call this method to add a permanent (JVM lifetime) alias of a class to an often shorter, name.
|
static void |
addPermanentClassFactory(Class<?> sourceClass,
JsonReader.ClassFactory factory)
Call this method to add a permanent (JVM lifetime) coercion of one
class to another during instance creation.
|
static void |
addPermanentCoercedType(Class<?> sourceClass,
Class<?> destinationClass)
Call this method to add a permanent (JVM lifetime) coercion of one
class to another during instance creation.
|
static void |
addPermanentReader(Class<?> c,
JsonReader.JsonClassReader reader)
Call this method to add a custom JSON reader to json-io.
|
ReadOptionsBuilder |
aliasTypeName(Class<?> type,
String alias) |
ReadOptionsBuilder |
aliasTypeName(String typeName,
String alias) |
ReadOptionsBuilder |
aliasTypeNames(Map<String,String> aliasTypeNames) |
ReadOptionsBuilder |
allowNanAndInfinity(boolean allowNanAndInfinity) |
static void |
assignInstantiator(Class<?> classToCreate,
JsonReader.ClassFactory factory) |
ReadOptions |
build() |
ReadOptionsBuilder |
classLoader(ClassLoader classLoader) |
ReadOptionsBuilder |
closeStream(boolean closeStream) |
ReadOptionsBuilder |
coerceClass(String sourceClassName,
Class<?> destClass)
Coerce a class from one type (named in the JSON) to another type.
|
ReadOptionsBuilder |
failOnUnknownType(boolean fail) |
ReadOptionsBuilder |
maxDepth(int maxDepth) |
ReadOptionsBuilder |
missingFieldHandler(JsonReader.MissingFieldHandler missingFieldHandler) |
ReadOptionsBuilder |
replaceClassFactories(Map<Class<?>,? extends JsonReader.ClassFactory> factories)
Associate multiple ClassFactory instances to Classes that needs help being constructed and read in.
|
ReadOptionsBuilder |
replaceCustomReaderClasses(Map<? extends Class<?>,? extends JsonReader.JsonClassReader> customReaderClasses) |
ReadOptionsBuilder |
replaceNotCustomReaderClasses(Collection<Class<?>> notCustomClasses) |
ReadOptionsBuilder |
returnAsJavaObjects()
Return as JAVA_OBJECT's the returned value will be of the class type passed into JsonReader.toJava(json, rootClass).
|
ReadOptionsBuilder |
returnAsNativeJsonObjects()
Set to return as JSON_OBJECTS's (faster, useful for large, more simple object data sets).
|
ReadOptionsBuilder |
setCharset(Charset charset) |
ReadOptionsBuilder |
setFalseCharacter(Character ch) |
ReadOptionsBuilder |
setLocale(Locale locale) |
ReadOptionsBuilder |
setTrueCharacter(Character ch) |
ReadOptionsBuilder |
setZoneId(ZoneId zoneId) |
ReadOptionsBuilder |
unknownTypeClass(Class<?> c)
Set a class to use when the JSON reader cannot instantiate a class.
|
public static void addPermanentClassFactory(Class<?> sourceClass, JsonReader.ClassFactory factory)
sourceClass
- String class name (fully qualified name) that will be coerced to another type.factory
- JsonReader.ClassFactory instance which can create the sourceClass and load it's contents,
using passed in JsonValues (JsonObject or JsonArray).public static void addPermanentCoercedType(Class<?> sourceClass, Class<?> destinationClass)
sourceClass
- String class name (fully qualified name) that will be coerced to another type.destinationClass
- Class to coerce to. For example, java.util.Collections$EmptyList to java.util.ArrayList.public static void addPermanentAlias(Class<?> sourceClass, String alias)
sourceClass
- String class name (fully qualified name) that will be aliased by a shorter name in the JSON.alias
- Shorter alias name, for example, "ArrayList" as opposed to "java.util.ArrayList"public static void addPermanentReader(Class<?> c, JsonReader.JsonClassReader reader)
c
- Class to assign a custom JSON reader toreader
- The JsonClassReader which will read the custom JSON format of 'c'public static void assignInstantiator(Class<?> classToCreate, JsonReader.ClassFactory factory)
classToCreate
- Class that will need to use a JsonReader.ClassFactory for instantiation and loading.factory
- JsonReader.ClassFactory instance that has been created to instantiate a difficult
to create and load class (class c).public ReadOptions build()
public ReadOptionsBuilder addNotCustomReaderClass(Class<?> notCustomClass)
notCustomClass
- Class to add to the not-customized list.public ReadOptionsBuilder replaceNotCustomReaderClasses(Collection<Class<?>> notCustomClasses)
notCustomClasses
- initialize the list of classes on the non-customized list. All prior associations
will be dropped and this Collection will establish the new list.public ReadOptionsBuilder addConverterOverride(Class<?> source, Class<?> target, com.cedarsoftware.util.convert.Convert<?> conversionFunction)
source
- source class.target
- target class.conversionFunction
- functional interface to run Conversion.public ReadOptionsBuilder replaceCustomReaderClasses(Map<? extends Class<?>,? extends JsonReader.JsonClassReader> customReaderClasses)
customReaderClasses
- Map of Class to JsonReader.JsonClassReader. Establish the passed in Map as the
established Map of custom readers to be used when reading JSON. Using this method
more than once, will set the custom readers to only the values from the Set in
the last call made.public ReadOptionsBuilder addCustomReaderClass(Class<?> clazz, JsonReader.JsonClassReader customReader)
clazz
- Class to add a custom reader for.customReader
- JsonClassReader to use when the passed in Class is encountered during serialization.
Custom readers are passed an empty instance. Use a ClassFactory if you want to instantiate
and load the class in one step.public ReadOptionsBuilder replaceClassFactories(Map<Class<?>,? extends JsonReader.ClassFactory> factories)
factories
- Map of entries that are Class to Factory. The Factory class knows how to instantiate
and load the class associated to it.public ReadOptionsBuilder addClassFactory(Class<?> clazz, JsonReader.ClassFactory factory)
clazz
- Class that is difficult to instantiate.factory
- Class written to instantiate the 'clazz' and load it's values.public ReadOptionsBuilder returnAsNativeJsonObjects()
public ReadOptionsBuilder returnAsJavaObjects()
public ReadOptionsBuilder classLoader(ClassLoader classLoader)
classLoader
- ClassLoader to use when reading JSON to resolve String named classes.public ReadOptionsBuilder failOnUnknownType(boolean fail)
fail
- boolean indicating whether we should fail on unknown type encountered.public ReadOptionsBuilder unknownTypeClass(Class<?> c)
c
- Class to instantiate when a String specified class in the JSON cannot be instantiated. Set to null
if you want a JsonIoException to be thrown when this happens.public ReadOptionsBuilder closeStream(boolean closeStream)
closeStream
- boolean set to 'true' to have JsonIo close the InputStream when it is finished reading
from it. The default is 'true'. If false, the InputStream will not be closed, allowing
you to continue reading further. Example, NDJSON that has new line eliminated JSON
objects repeated.public ReadOptionsBuilder maxDepth(int maxDepth)
maxDepth
- int maximum of the depth that JSON Objects {...} can be nested. Set this to prevent
security risk from StackOverflow attack vectors.public ReadOptionsBuilder allowNanAndInfinity(boolean allowNanAndInfinity)
allowNanAndInfinity
- boolean 'allowNanAndInfinity' setting. true will allow Double and Floats to be
read in as NaN and +Inf, -Inf [infinity], false and a JsonIoException will be
thrown if these values are encounteredpublic ReadOptionsBuilder aliasTypeNames(Map<String,String> aliasTypeNames)
aliasTypeNames
- Map containing String class names to alias names. The passed in Map will
be copied, and be the new baseline settings.public ReadOptionsBuilder aliasTypeName(Class<?> type, String alias)
type
- String class namealias
- String shorter name to use, typically.public ReadOptionsBuilder aliasTypeName(String typeName, String alias)
typeName
- String class namealias
- String shorter name to use, typically.public ReadOptionsBuilder setLocale(Locale locale)
locale
- target locale for conversionspublic ReadOptionsBuilder setCharset(Charset charset)
charset
- source charset for conversionspublic ReadOptionsBuilder setZoneId(ZoneId zoneId)
zoneId
- source charset for conversionspublic ReadOptionsBuilder setTrueCharacter(Character ch)
ch
- Character used when converting true -> charpublic ReadOptionsBuilder setFalseCharacter(Character ch)
ch
- Character used when converting false -> charpublic ReadOptionsBuilder addCustomOption(String key, Object value)
key
- String name of the custom optionvalue
- Object value of the custom optionpublic ReadOptionsBuilder coerceClass(String sourceClassName, Class<?> destClass)
sourceClassName
- String class name to coerce to another type.destClass
- Class to coerce into.public ReadOptionsBuilder missingFieldHandler(JsonReader.MissingFieldHandler missingFieldHandler)
missingFieldHandler
- JsonReader.MissingFieldHandler implementation to call. This method will be
called when a field in the JSON is read in, yet there is no corresponding field on the destination object to
receive the value.public ReadOptionsBuilder addNonReferenceableClass(Class<?> clazz)
clazz
- class to add to be considered a non-referenceable object. Just like an "int" for example, any
class added here will never use an @id/@ref pair. The downside, is that when read,
each instance, even if the same as another, will use memory.Copyright © 2024. All rights reserved.