Package com.cedarsoftware.io
Class ReadOptionsBuilder
java.lang.Object
com.cedarsoftware.io.ReadOptionsBuilder
Builder class for building the writeOptions.
- Author:
- John DeRegnaucourt ([email protected]), 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
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 TypeClassDescriptionstatic interface
static class
-
Constructor Summary
ConstructorsConstructorDescriptionStart with default optionsStart with a copy of another ReadOptions. -
Method Summary
Modifier and TypeMethodDescriptionaddClassFactory
(Class<?> clazz, JsonReader.ClassFactory factory) Associate a ClassFactory to a Class that needs help being constructed and read in.addConverterOverride
(Class<?> source, Class<?> target, com.cedarsoftware.util.convert.Convert<?> conversionFunction) addCustomOption
(String key, Object value) Add a custom option, which may be useful when writing custom readers.addCustomReaderClass
(Class<T> clazz, JsonReader.JsonClassReader<? super T> customReader) addFieldFilter
(FieldFilter filter) Add a class to the field filter list - allows adding more field filter typesaddInjectorFactory
(InjectorFactory factory) Add a class to the injector factory list - allows to add injector to the classaddNonReferenceableClass
(Class<?> clazz) 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
addPermanentAllowNanAndInfinity
(boolean allowNanAndInfinity) All new ReadOptions instances will use this NaN and Infinity handling setting.static void
addPermanentClassFactory
(Class<?> sourceClass, JsonReader.ClassFactory factory) Call this method to add a factory class that will be used to create instances of another class.static void
addPermanentCloseStream
(boolean closeStream) All new ReadOptions instances will use this stream closing setting.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
addPermanentCollectionLoadFactor
(float collectionLoadFactor) All new ReadOptions instances will use this collection load factor.static void
addPermanentDefaultCollectionCapacity
(int defaultCollectionCapacity) All new ReadOptions instances will use this default collection capacity.static void
addPermanentFailOnUnknownType
(boolean failOnUnknownType) All new ReadOptions instances will use this unknown type handling setting.static void
addPermanentLargeThreadLocalBufferSize
(int largeThreadLocalBufferSize) Set a permanent (JVM lifecycle) size for ThreadLocal large string processing buffers during JSON parsing.static void
addPermanentLinearSearchThreshold
(int linearSearchThreshold) All new ReadOptions instances will use this linear search threshold.static void
addPermanentLruSize
(int lruSize) All new ReadOptions instances will use this LRU cache size.static void
addPermanentMaxAllowedLength
(int maxAllowedLength) Set a permanent (JVM lifecycle) maximum allowed length for argument character processing in MetaUtils.static void
addPermanentMaxDepth
(int maxDepth) All new ReadOptions instances will use this maximum parsing depth.static void
addPermanentMaxEnumNameLength
(int maxEnumNameLength) Set a permanent (JVM lifecycle) maximum length of enum name strings during JSON processing.static void
addPermanentMaxFileContentSize
(int maxFileContentSize) Set a permanent (JVM lifecycle) maximum file content size when loading resource files in MetaUtils.static void
addPermanentMaxIdValue
(long maxIdValue) Set a permanent (JVM lifecycle) maximum absolute value for @id and @ref values during JSON processing.static void
addPermanentMaxLineCount
(int maxLineCount) Set a permanent (JVM lifecycle) maximum number of lines when processing resource files in MetaUtils.static void
addPermanentMaxLineLength
(int maxLineLength) Set a permanent (JVM lifecycle) maximum length per line when processing resource files in MetaUtils.static void
addPermanentMaxMapsToRehash
(int maxMapsToRehash) Set a permanent (JVM lifecycle) maximum number of maps that can be queued for rehashing during JSON processing.static void
addPermanentMaxMissingFields
(int maxMissingFields) Set a permanent (JVM lifecycle) maximum number of missing fields that can be tracked during JSON processing.static void
addPermanentMaxObjectReferences
(int maxObjectReferences) Set a permanent (JVM lifecycle) maximum number of object references that can be tracked during JSON processing.static void
addPermanentMaxReferenceChainDepth
(int maxReferenceChainDepth) Set a permanent (JVM lifecycle) maximum depth of reference chains that can be traversed during JSON processing.static void
addPermanentMaxStackDepth
(int maxStackDepth) Set a permanent (JVM lifecycle) maximum traversal stack depth allowed during JSON processing.static void
addPermanentMaxTypeResolutionCacheSize
(int maxTypeResolutionCacheSize) Call this method to set a permanent (JVM lifetime) maximum type resolution cache size for JsonValue.static void
addPermanentMaxUnresolvedReferences
(int maxUnresolvedReferences) Set a permanent (JVM lifecycle) maximum number of unresolved references allowed during JSON processing.static void
addPermanentMinCollectionCapacity
(int minCollectionCapacity) All new ReadOptions instances will use this minimum collection capacity.static void
addPermanentNonReferenceableClass
(Class<?> clazz) Add a class permanently (JVM lifecycle) to the Non-referenceable list.static void
addPermanentNonStandardSetter
(Class<?> clazz, String fieldName, String alias) Add the String name of the "setter" (injector) associated to the field name. mappings for the passed in Class.static void
addPermanentNotCustomReadClass
(Class<?> clazz) Add a class permanently (JVM lifecycle) to the Not-Custom reader list.static void
addPermanentNotImportedField
(Class<?> clazz, String fieldName) Add a field to a class that should not be imported.static void
addPermanentReader
(Class<?> c, JsonReader.JsonClassReader reader) Call this method to add a custom JSON reader to json-io.static void
addPermanentStringBufferSize
(int stringBufferSize) Set a permanent (JVM lifecycle) initial capacity for string parsing buffers during JSON processing.static void
addPermanentThreadLocalBufferSize
(int threadLocalBufferSize) Set a permanent (JVM lifecycle) size for ThreadLocal string processing buffers during JSON parsing.aliasTypeName
(Class<?> type, String alias) aliasTypeName
(String typeName, String alias) aliasTypeNames
(Map<String, String> aliasTypeNames) allowNanAndInfinity
(boolean allowNanAndInfinity) static void
assignInstantiator
(Class<?> classToCreate, JsonReader.ClassFactory factory) Deprecated.build()
classLoader
(ClassLoader classLoader) closeStream
(boolean closeStream) coerceClass
(String sourceClassName, Class<?> destClass) Coerce a class from one type (named in the JSON) to another type.collectionLoadFactor
(float collectionLoadFactor) defaultCollectionCapacity
(int defaultCollectionCapacity) failOnUnknownType
(boolean fail) Set Floating Point types to be returned as BigDecimals.Set Floating Point types to be returned as either Doubles or BigDecimals, depending on precision required to hold the number sourced from JSON.Set Floating Point types to be returned as Doubles.static ReadOptions
Set Integer Types to be returned as BigIntegers.Set Integer Types to be returned as either Longs or BigIntegers, depending on precision required to hold the number sourced from JSON.Set Integer Types to be returned as Longs.largeThreadLocalBufferSize
(int largeThreadLocalBufferSize) linearSearchThreshold
(int linearSearchThreshold) lruSize
(int lruSize) maxAllowedLength
(int maxAllowedLength) maxDepth
(int maxDepth) maxEnumNameLength
(int maxEnumNameLength) maxFileContentSize
(int maxFileContentSize) maxIdValue
(long maxIdValue) maxLineCount
(int maxLineCount) maxLineLength
(int maxLineLength) maxMapsToRehash
(int maxMapsToRehash) maxMissingFields
(int maxMissingFields) maxObjectReferences
(int maxObjectReferences) maxReferenceChainDepth
(int maxReferenceChainDepth) maxStackDepth
(int maxStackDepth) maxTypeResolutionCacheSize
(int maxTypeResolutionCacheSize) maxUnresolvedReferences
(int maxUnresolvedReferences) minCollectionCapacity
(int minCollectionCapacity) missingFieldHandler
(JsonReader.MissingFieldHandler missingFieldHandler) removeAliasTypeNameMatching
(String typeNamePattern) Remove alias entries from this ReadOptionsBuilder instance where the Java fully qualified string class name matches the passed in wildcard pattern.static void
removePermanentAliasTypeNamesMatching
(String classNamePattern) Call this method to remove alias patterns from the ReadsOptionsBuilder.replaceClassFactories
(Map<? extends Class<?>, ? extends JsonReader.ClassFactory> factories) Associate multiple ClassFactory instances to Classes that needs help being constructed and read in.replaceCustomReaderClasses
(Map<? extends Class<?>, ? extends JsonReader.JsonClassReader> customReaderClasses) replaceNotCustomReaderClasses
(Collection<? extends Class<?>> notCustomClasses) Return as JAVA_OBJECT's the returned value will be of the class type passed into JsonReader.toJava(json, rootClass).Set to return as JSON_OBJECTS's (faster, useful for large, more simple object data sets).Deprecated.usereturnAsJsonObjects()
instead.setCharset
(Charset charset) stringBufferSize
(int stringBufferSize) threadLocalBufferSize
(int threadLocalBufferSize) unknownTypeClass
(Class<?> c) Set a class to use when the JSON reader cannot instantiate a class.
-
Constructor Details
-
ReadOptionsBuilder
public ReadOptionsBuilder()Start with default options -
ReadOptionsBuilder
Start with a copy of another ReadOptions. If copy is null, then you get the default options.
-
-
Method Details
-
getDefaultReadOptions
- Returns:
- Default ReadOptions - no construction needed, unmodifiable.
-
addPermanentClassFactory
Call this method to add a factory class that will be used to create instances of another class. This is useful when you have a class that `json-io` cannot instantiate due to private or other constructor issues. Add a JsonReader.ClassFactory class (that you implement) and associate it to the passed in 'classToCreate'. Your JsonReader.ClassFactory class will be called with the Map (JsonObject) that contains the { ... } that should be loaded into your class. It is your ClassFactory implementations job to create the instance of the associated class, and then copy the values from the passed in Map to the Java instance you created.- Parameters:
sourceClass
- String class name (fully qualified name) to associate to your ClassFactory implementation.factory
- JsonReader.ClassFactory your ClassFactory implementation that creates/loads the associated class using the Map (JsonObject) of data passed to it.
-
assignInstantiator
@Deprecated public static void assignInstantiator(Class<?> classToCreate, JsonReader.ClassFactory factory) Deprecated.- Parameters:
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).
-
addPermanentCoercedType
Call this method to add a permanent (JVM lifetime) coercion of one class to another during instance creation. Examples of classes that might need this are proxied classes such as HibernateBags, etc. That you want to create as regular jvm collections.- Parameters:
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.
-
addPermanentAlias
Call this method to add a permanent (JVM lifetime) alias of a class to an often shorter, name.- Parameters:
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"
-
removePermanentAliasTypeNamesMatching
Call this method to remove alias patterns from the ReadsOptionsBuilder. Be careful doing so. In a micro-services environment, you want the receiving services to know as many substitutions as possible. It is important to control the aliases on the "written" side, to ensure that written JSON does not include aliases that the receiving micro-services do not yet 'understand.' Therefore, you should rarely need this API.
This API matches your wildcard pattern of *, ?, and characters against class names in its cache. It removes the entries (className to aliasName) from the cache to prevent the resultant classes from being aliased during output.- Parameters:
classNamePattern
- String pattern to match class names. This String matches using a wild-card pattern, where * matches anything and ? matches one character. As many * or ? can be used as needed.
-
addPermanentReader
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 custom 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'
-
addPermanentNonReferenceableClass
Add a class permanently (JVM lifecycle) to the Non-referenceable list. All new ReadOptions instances created will automatically start with this, and you will not need to add it into the ReadOptions through the ReadOptionsBuilder each time.- Parameters:
clazz
- Class to be added to the non-reference list. A class that is on this list, will be written out to the JSON fully, each time it is encountered, and never be written with an @ref. Use for very simple, atomic type (single field classes).
-
addPermanentNotCustomReadClass
Add a class permanently (JVM lifecycle) to the Not-Custom reader list. All new ReadOptions instances created will automatically start with this, and you will not need to add it into the ReadOptions through the ReadOptionsBuilder each time.- Parameters:
clazz
- Class to be added to the Not-Custom reader list. A class that is on this list, will not use a Custom Reader or Class Factory when read from the JSON.
-
addPermanentNotImportedField
Add a field to a class that should not be imported. Any class's field added here will be excluded when read from the JSON. The value will not be set (injected) into the associated Java instance.- Parameters:
clazz
- Class on which fields will be excluded.fieldName
- String field name to exclude for the given class.
-
addPermanentNonStandardSetter
Add the String name of the "setter" (injector) associated to the field name. mappings for the passed in Class.- Parameters:
clazz
- Class to which the association will be added.fieldName
- String name of field that has a non-standard setter (injector)alias
- String name of setter method that is used to write to the fieldName. An example is Throwable's initCause() setter which does not follow a standard naming convention (should be 'setCause()'). In this example, use addPermanentNonStandardSetter(Throwable.class, "cause", "initCause").
-
addPermanentMaxUnresolvedReferences
public static void addPermanentMaxUnresolvedReferences(int maxUnresolvedReferences) Set a permanent (JVM lifecycle) maximum number of unresolved references allowed during JSON processing. All new ReadOptions instances created will automatically start with this setting, preventing the need to configure it for each ReadOptions instance.- Parameters:
maxUnresolvedReferences
- int maximum number of unresolved references allowed. Set this to prevent memory exhaustion from DoS attacks via unbounded forward references. Use Integer.MAX_VALUE for unlimited (backward compatible default).
-
addPermanentMaxStackDepth
public static void addPermanentMaxStackDepth(int maxStackDepth) Set a permanent (JVM lifecycle) maximum traversal stack depth allowed during JSON processing. All new ReadOptions instances created will automatically start with this setting, preventing the need to configure it for each ReadOptions instance.- Parameters:
maxStackDepth
- int maximum traversal stack depth allowed. Set this to prevent stack overflow attacks via deeply nested structures. Use Integer.MAX_VALUE for unlimited (backward compatible default).
-
addPermanentMaxMapsToRehash
public static void addPermanentMaxMapsToRehash(int maxMapsToRehash) Set a permanent (JVM lifecycle) maximum number of maps that can be queued for rehashing during JSON processing. All new ReadOptions instances created will automatically start with this setting, preventing the need to configure it for each ReadOptions instance.- Parameters:
maxMapsToRehash
- int maximum number of maps that can be queued for rehashing. Set this to prevent memory exhaustion from DoS attacks via excessive map creation. Use Integer.MAX_VALUE for unlimited (backward compatible default).
-
addPermanentMaxMissingFields
public static void addPermanentMaxMissingFields(int maxMissingFields) Set a permanent (JVM lifecycle) maximum number of missing fields that can be tracked during JSON processing. All new ReadOptions instances created will automatically start with this setting, preventing the need to configure it for each ReadOptions instance.- Parameters:
maxMissingFields
- int maximum number of missing fields that can be tracked. Set this to prevent memory exhaustion from DoS attacks via excessive missing field tracking. Use Integer.MAX_VALUE for unlimited (backward compatible default).
-
addPermanentMaxObjectReferences
public static void addPermanentMaxObjectReferences(int maxObjectReferences) Set a permanent (JVM lifecycle) maximum number of object references that can be tracked during JSON processing. All new ReadOptions instances created will automatically start with this setting, preventing the need to configure it for each ReadOptions instance.- Parameters:
maxObjectReferences
- int maximum number of object references that can be tracked. Set this to prevent memory exhaustion from DoS attacks via unbounded object reference growth. Use 10,000,000 for backward compatible default.
-
addPermanentMaxReferenceChainDepth
public static void addPermanentMaxReferenceChainDepth(int maxReferenceChainDepth) Set a permanent (JVM lifecycle) maximum depth of reference chains that can be traversed during JSON processing. All new ReadOptions instances created will automatically start with this setting, preventing the need to configure it for each ReadOptions instance.- Parameters:
maxReferenceChainDepth
- int maximum depth of reference chains that can be traversed. Set this to prevent infinite loops from circular reference attacks. Use 10,000 for backward compatible default.
-
addPermanentMaxEnumNameLength
public static void addPermanentMaxEnumNameLength(int maxEnumNameLength) Set a permanent (JVM lifecycle) maximum length of enum name strings during JSON processing. All new ReadOptions instances created will automatically start with this setting, preventing the need to configure it for each ReadOptions instance.- Parameters:
maxEnumNameLength
- int maximum length of enum name strings. Set this to prevent memory exhaustion from DoS attacks via excessively long enum names. Use 256 for backward compatible default.
-
addPermanentMaxIdValue
public static void addPermanentMaxIdValue(long maxIdValue) Set a permanent (JVM lifecycle) maximum absolute value for @id and @ref values during JSON processing. All new ReadOptions instances created will automatically start with this setting, preventing the need to configure it for each ReadOptions instance.- Parameters:
maxIdValue
- long maximum absolute value for ID values. Set this to prevent issues with extreme ID values that could cause problems. Use 1,000,000,000 for backward compatible default.
-
addPermanentStringBufferSize
public static void addPermanentStringBufferSize(int stringBufferSize) Set a permanent (JVM lifecycle) initial capacity for string parsing buffers during JSON processing. All new ReadOptions instances created will automatically start with this setting, preventing the need to configure it for each ReadOptions instance.- Parameters:
stringBufferSize
- int initial capacity for string parsing buffers. This affects memory allocation for string parsing operations. Use 256 for backward compatible default.
-
addPermanentThreadLocalBufferSize
public static void addPermanentThreadLocalBufferSize(int threadLocalBufferSize) Set a permanent (JVM lifecycle) size for ThreadLocal string processing buffers during JSON parsing. All new ReadOptions instances created will automatically start with this setting, preventing the need to configure it for each ReadOptions instance.- Parameters:
threadLocalBufferSize
- int size for ThreadLocal buffers. This affects memory allocation for string processing operations. Use 1024 for backward compatible default.
-
addPermanentLargeThreadLocalBufferSize
public static void addPermanentLargeThreadLocalBufferSize(int largeThreadLocalBufferSize) Set a permanent (JVM lifecycle) size for ThreadLocal large string processing buffers during JSON parsing. All new ReadOptions instances created will automatically start with this setting, preventing the need to configure it for each ReadOptions instance.- Parameters:
largeThreadLocalBufferSize
- int size for large ThreadLocal buffers. This affects memory allocation for large string processing operations. Use 8192 for backward compatible default.
-
addPermanentMaxAllowedLength
public static void addPermanentMaxAllowedLength(int maxAllowedLength) Set a permanent (JVM lifecycle) maximum allowed length for argument character processing in MetaUtils. All new ReadOptions instances created will automatically start with this setting, preventing the need to configure it for each ReadOptions instance.- Parameters:
maxAllowedLength
- int maximum allowed length for argument processing. Set this to prevent memory exhaustion when processing large arguments. Use 65536 (64KB) for backward compatible default.
-
addPermanentMaxFileContentSize
public static void addPermanentMaxFileContentSize(int maxFileContentSize) Set a permanent (JVM lifecycle) maximum file content size when loading resource files in MetaUtils. All new ReadOptions instances created will automatically start with this setting, preventing the need to configure it for each ReadOptions instance.- Parameters:
maxFileContentSize
- int maximum file content size in bytes. Set this to prevent memory exhaustion from oversized resource files. Use 1048576 (1MB) for backward compatible default.
-
addPermanentMaxLineCount
public static void addPermanentMaxLineCount(int maxLineCount) Set a permanent (JVM lifecycle) maximum number of lines when processing resource files in MetaUtils. All new ReadOptions instances created will automatically start with this setting, preventing the need to configure it for each ReadOptions instance.- Parameters:
maxLineCount
- int maximum number of lines. Set this to prevent resource exhaustion from files with excessive line counts. Use 10000 for backward compatible default.
-
addPermanentMaxLineLength
public static void addPermanentMaxLineLength(int maxLineLength) Set a permanent (JVM lifecycle) maximum length per line when processing resource files in MetaUtils. All new ReadOptions instances created will automatically start with this setting, preventing the need to configure it for each ReadOptions instance.- Parameters:
maxLineLength
- int maximum length per line. Set this to prevent memory exhaustion from excessively long lines. Use 8192 (8KB) for backward compatible default.
-
addPermanentMaxTypeResolutionCacheSize
public static void addPermanentMaxTypeResolutionCacheSize(int maxTypeResolutionCacheSize) Call this method to set a permanent (JVM lifetime) maximum type resolution cache size for JsonValue. All ReadOptions instances will be initialized with this value unless explicitly overridden.- Parameters:
maxTypeResolutionCacheSize
- int maximum size of the type resolution cache used by JsonValue. Must be at least 1. Default is 1,000.
-
addPermanentDefaultCollectionCapacity
public static void addPermanentDefaultCollectionCapacity(int defaultCollectionCapacity) All new ReadOptions instances will use this default collection capacity.- Parameters:
defaultCollectionCapacity
- int default initial capacity for collections during JSON processing. Default is 16 for backward compatibility.
-
addPermanentCollectionLoadFactor
public static void addPermanentCollectionLoadFactor(float collectionLoadFactor) All new ReadOptions instances will use this collection load factor.- Parameters:
collectionLoadFactor
- float load factor for hash-based collections during JSON processing. Default is 0.75f for backward compatibility.
-
addPermanentMinCollectionCapacity
public static void addPermanentMinCollectionCapacity(int minCollectionCapacity) All new ReadOptions instances will use this minimum collection capacity.- Parameters:
minCollectionCapacity
- int minimum collection capacity for collections during JSON processing. Default is 16 for backward compatibility.
-
addPermanentLinearSearchThreshold
public static void addPermanentLinearSearchThreshold(int linearSearchThreshold) All new ReadOptions instances will use this linear search threshold.- Parameters:
linearSearchThreshold
- int threshold for switching between linear and binary search in JsonObject operations. Default is 8 for backward compatibility.
-
addPermanentMaxDepth
public static void addPermanentMaxDepth(int maxDepth) All new ReadOptions instances will use this maximum parsing depth.- Parameters:
maxDepth
- int maximum depth for JSON parsing to prevent stack overflow attacks. Default is 1000 for backward compatibility.
-
addPermanentLruSize
public static void addPermanentLruSize(int lruSize) All new ReadOptions instances will use this LRU cache size.- Parameters:
lruSize
- int size of the LRU cache for object references during JSON processing. Default is 500 for backward compatibility.
-
addPermanentAllowNanAndInfinity
public static void addPermanentAllowNanAndInfinity(boolean allowNanAndInfinity) All new ReadOptions instances will use this NaN and Infinity handling setting.- Parameters:
allowNanAndInfinity
- boolean whether to allow NaN and Infinity values in JSON parsing. Default is true for backward compatibility.
-
addPermanentFailOnUnknownType
public static void addPermanentFailOnUnknownType(boolean failOnUnknownType) All new ReadOptions instances will use this unknown type handling setting.- Parameters:
failOnUnknownType
- boolean whether to fail when encountering unknown types in JSON. Default is false for backward compatibility.
-
addPermanentCloseStream
public static void addPermanentCloseStream(boolean closeStream) All new ReadOptions instances will use this stream closing setting.- Parameters:
closeStream
- boolean whether to close input streams after JSON parsing. Default is true for backward compatibility.
-
build
- Returns:
- ReadOptions - built options
-
addInjectorFactory
Add a class to the injector factory list - allows to add injector to the class- Parameters:
factory
- Class to add to the injector factory list.- Returns:
- ReadOptionsBuilder for chained access.
-
addFieldFilter
Add a class to the field filter list - allows adding more field filter types- Parameters:
filter
- FieldFilter to add- Returns:
- ReadOptionsBuilder for chained access.
-
addNotCustomReaderClass
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).- Parameters:
notCustomClass
- Class to add to the not-customized list.- Returns:
- ReadOptionsBuilder for chained access.
-
replaceNotCustomReaderClasses
public ReadOptionsBuilder replaceNotCustomReaderClasses(Collection<? extends Class<?>> notCustomClasses) - Parameters:
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.- Returns:
- ReadOptionsBuilder for chained access.
-
addConverterOverride
public ReadOptionsBuilder addConverterOverride(Class<?> source, Class<?> target, com.cedarsoftware.util.convert.Convert<?> conversionFunction) - Parameters:
source
- source class.target
- target class.conversionFunction
- functional interface to run Conversion.- Returns:
- ReadOptionsBuilder for chained access.
-
replaceCustomReaderClasses
public ReadOptionsBuilder replaceCustomReaderClasses(Map<? extends Class<?>, ? extends JsonReader.JsonClassReader> customReaderClasses) - Parameters:
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.- Returns:
- ReadOptionsBuilder for chained access.
-
addCustomReaderClass
public <T> ReadOptionsBuilder addCustomReaderClass(Class<T> clazz, JsonReader.JsonClassReader<? super T> customReader) - Parameters:
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.- Returns:
- ReadOptionsBuilder for chained access.
-
replaceClassFactories
public ReadOptionsBuilder replaceClassFactories(Map<? extends Class<?>, ? extends JsonReader.ClassFactory> factories) Associate multiple ClassFactory instances to Classes that needs help being constructed and read in.- Parameters:
factories
- Map of entries that are Class to Factory. The Factory class knows how to instantiate and load the class associated to it.- Returns:
- ReadOptionsBuilder for chained access.
-
addClassFactory
Associate a ClassFactory to a Class that needs help being constructed and read in.- Parameters:
clazz
- Class that is difficult to instantiate.factory
- Class written to instantiate the 'clazz' and load it's values.- Returns:
- ReadOptionsBuilder for chained access.
-
returnAsNativeJsonObjects
Deprecated.usereturnAsJsonObjects()
instead.Set to return as JSON_OBJECTS's (faster, useful for large, more simple object data sets). This returns as native json types (Map, Object[], long, double, boolean) -
returnAsJsonObjects
Set to return as JSON_OBJECTS's (faster, useful for large, more simple object data sets). This returns as native json types (Map, Object[], long, double, boolean) -
returnAsJavaObjects
Return as JAVA_OBJECT's the returned value will be of the class type passed into JsonReader.toJava(json, rootClass). This mode is good for cloning exact objects. -
floatPointDouble
Set Floating Point types to be returned as Doubles. This is the default. -
floatPointBigDecimal
Set Floating Point types to be returned as BigDecimals. -
floatPointBoth
Set Floating Point types to be returned as either Doubles or BigDecimals, depending on precision required to hold the number sourced from JSON. -
integerTypeLong
Set Integer Types to be returned as Longs. This is the default. -
integerTypeBigInteger
Set Integer Types to be returned as BigIntegers. -
integerTypeBoth
Set Integer Types to be returned as either Longs or BigIntegers, depending on precision required to hold the number sourced from JSON. -
classLoader
- Parameters:
classLoader
- ClassLoader to use when reading JSON to resolve String named classes.- Returns:
- ReadOptionsBuilder for chained access.
-
failOnUnknownType
- Parameters:
fail
- boolean indicating whether we should fail on unknown type encountered.- Returns:
- ReadOptionsBuilder for chained access.
-
unknownTypeClass
Set a class to use when the JSON reader cannot instantiate a class. When that happens, it will throw a JsonIoException() if no 'unknownTypeClass' is set, otherwise it will create the instance of the class specified as the 'unknownTypeClass.' A common one to use, for example, if java.util.LinkedHashMap.- Parameters:
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.- Returns:
- ReadOptionsBuilder for chained access.
-
closeStream
- Parameters:
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.- Returns:
- ReadOptionsBuilder for chained access.
-
maxDepth
- Parameters:
maxDepth
- int maximum of the depth that JSON Objects {...} can be nested. Set this to prevent security risk from StackOverflow attack vectors.- Returns:
- ReadOptionsBuilder for chained access.
-
maxUnresolvedReferences
- Parameters:
maxUnresolvedReferences
- int maximum number of unresolved references allowed during JSON processing. Set this to prevent memory exhaustion from DoS attacks via unbounded forward references. Default is Integer.MAX_VALUE (unlimited) for backward compatibility.- Returns:
- ReadOptionsBuilder for chained access.
-
maxStackDepth
- Parameters:
maxStackDepth
- int maximum traversal stack depth allowed during JSON processing. Set this to prevent stack overflow attacks via deeply nested structures. Default is Integer.MAX_VALUE (unlimited) for backward compatibility.- Returns:
- ReadOptionsBuilder for chained access.
-
maxMapsToRehash
- Parameters:
maxMapsToRehash
- int maximum number of maps that can be queued for rehashing during JSON processing. Set this to prevent memory exhaustion from DoS attacks via excessive map creation. Default is Integer.MAX_VALUE (unlimited) for backward compatibility.- Returns:
- ReadOptionsBuilder for chained access.
-
maxMissingFields
- Parameters:
maxMissingFields
- int maximum number of missing fields that can be tracked during JSON processing. Set this to prevent memory exhaustion from DoS attacks via excessive missing field tracking. Default is Integer.MAX_VALUE (unlimited) for backward compatibility.- Returns:
- ReadOptionsBuilder for chained access.
-
maxObjectReferences
- Parameters:
maxObjectReferences
- int maximum number of object references that can be tracked during JSON processing. Set this to prevent memory exhaustion from DoS attacks via unbounded object reference growth. Default is 10,000,000 for backward compatibility.- Returns:
- ReadOptionsBuilder for chained access.
-
maxReferenceChainDepth
- Parameters:
maxReferenceChainDepth
- int maximum depth of reference chains that can be traversed during JSON processing. Set this to prevent infinite loops from circular reference attacks. Default is 10,000 for backward compatibility.- Returns:
- ReadOptionsBuilder for chained access.
-
maxEnumNameLength
- Parameters:
maxEnumNameLength
- int maximum length of enum name strings during JSON processing. Set this to prevent memory exhaustion from DoS attacks via excessively long enum names. Default is 256 for backward compatibility.- Returns:
- ReadOptionsBuilder for chained access.
-
maxIdValue
- Parameters:
maxIdValue
- long maximum absolute value for @id and @ref values during JSON processing. Set this to prevent issues with extreme ID values that could cause problems. Default is 1,000,000,000 for backward compatibility.- Returns:
- ReadOptionsBuilder for chained access.
-
stringBufferSize
- Parameters:
stringBufferSize
- int initial capacity for string parsing buffers during JSON processing. This affects memory allocation for string parsing operations. Default is 256 for backward compatibility.- Returns:
- ReadOptionsBuilder for chained access.
-
threadLocalBufferSize
- Parameters:
threadLocalBufferSize
- int size for ThreadLocal string processing buffers during JSON parsing. This affects memory allocation for string processing operations. Default is 1024 for backward compatibility.- Returns:
- ReadOptionsBuilder for chained access.
-
largeThreadLocalBufferSize
- Parameters:
largeThreadLocalBufferSize
- int size for ThreadLocal large string processing buffers during JSON parsing. This affects memory allocation for large string processing operations. Default is 8192 for backward compatibility.- Returns:
- ReadOptionsBuilder for chained access.
-
maxAllowedLength
- Parameters:
maxAllowedLength
- int maximum allowed length for argument character processing in MetaUtils. Set this to prevent memory exhaustion when processing large arguments. Default is 65536 (64KB) for backward compatibility.- Returns:
- ReadOptionsBuilder for chained access.
-
maxFileContentSize
- Parameters:
maxFileContentSize
- int maximum file content size in bytes when loading resource files in MetaUtils. Set this to prevent memory exhaustion from oversized resource files. Default is 1048576 (1MB) for backward compatibility.- Returns:
- ReadOptionsBuilder for chained access.
-
maxLineCount
- Parameters:
maxLineCount
- int maximum number of lines when processing resource files in MetaUtils. Set this to prevent resource exhaustion from files with excessive line counts. Default is 10000 for backward compatibility.- Returns:
- ReadOptionsBuilder for chained access.
-
maxLineLength
- Parameters:
maxLineLength
- int maximum length per line when processing resource files in MetaUtils. Set this to prevent memory exhaustion from excessively long lines. Default is 8192 (8KB) for backward compatibility.- Returns:
- ReadOptionsBuilder for chained access.
-
maxTypeResolutionCacheSize
- Parameters:
maxTypeResolutionCacheSize
- int maximum size of the type resolution cache used by JsonValue. Default is 1,000 entries. This prevents unbounded memory growth while maintaining performance benefits. The cache is used to store whether Java Types are fully resolved (no type variables).- Returns:
- ReadOptionsBuilder for chained access.
-
defaultCollectionCapacity
- Parameters:
defaultCollectionCapacity
- int default initial capacity for collections during JSON processing. This affects memory allocation for collection factory operations. Default is 16 for backward compatibility.- Returns:
- ReadOptionsBuilder for chained access.
-
collectionLoadFactor
- Parameters:
collectionLoadFactor
- float load factor for hash-based collections during JSON processing. This affects hash collection performance and memory usage. Default is 0.75f for backward compatibility.- Returns:
- ReadOptionsBuilder for chained access.
-
minCollectionCapacity
- Parameters:
minCollectionCapacity
- int minimum collection capacity for collections during JSON processing. This sets a lower bound on collection sizes for performance reasons. Default is 16 for backward compatibility.- Returns:
- ReadOptionsBuilder for chained access.
-
linearSearchThreshold
- Parameters:
linearSearchThreshold
- int threshold for switching between linear and binary search in JsonObject operations. For arrays with size <= this threshold, linear search is used for better cache locality. Default is 8 for backward compatibility.- Returns:
- ReadOptionsBuilder for chained access.
-
lruSize
- Parameters:
lruSize
- int maximum size of the LRU cache that holds reflective information like fields of a Class and injectors associated to a class.- Returns:
- ReadOptionsBuilder for chained access.
-
allowNanAndInfinity
- Parameters:
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 encountered- Returns:
- ReadOptionsBuilder for chained access.
-
aliasTypeNames
- Parameters:
aliasTypeNames
- Map containing String class names to alias names. The passed in Map will be copied, and be the new baseline settings.- Returns:
- ReadOptionsBuilder for chained access.
-
aliasTypeName
- Parameters:
type
- Class to aliasalias
- String shorter name to use, typically.- Returns:
- ReadOptionsBuilder for chained access.
-
aliasTypeName
- Parameters:
typeName
- String class namealias
- String shorter name to use, typically.- Returns:
- ReadOptionsBuilder for chained access.
-
removeAliasTypeNameMatching
Remove alias entries from this ReadOptionsBuilder instance where the Java fully qualified string class name matches the passed in wildcard pattern.- Parameters:
typeNamePattern
- String pattern to match class names. This String matches using a wild-card pattern, where * matches anything and ? matches one character. As many * or ? can be used as needed.- Returns:
- ReadOptionsBuilder for chained access.
-
setLocale
- Parameters:
locale
- target locale for conversions- Returns:
- ReadOptionsBuilder for chained access.
-
setCharset
- Parameters:
charset
- source charset for conversions- Returns:
- ReadOptionsBuilder for chained access.
-
setZoneId
- Parameters:
zoneId
- source charset for conversions- Returns:
- ReadOptionsBuilder for chained access.
-
setTrueCharacter
- Parameters:
ch
- Character used when converting true -> char- Returns:
- ReadOptionsBuilder for chained access.
-
setFalseCharacter
- Parameters:
ch
- Character used when converting false -> char- Returns:
- ReadOptionsBuilder for chained access.
-
addCustomOption
Add a custom option, which may be useful when writing custom readers.- Parameters:
key
- String name of the custom optionvalue
- Object value of the custom option- Returns:
- ReadOptionsBuilder for chained access.
-
coerceClass
Coerce a class from one type (named in the JSON) to another type. For example, converting "java.util.Collections$SingletonSet" to a LinkedHashSet.class.- Parameters:
sourceClassName
- String class name to coerce to another type.destClass
- Class to coerce into.- Returns:
- ReadOptionsBuilder for chained access.
-
missingFieldHandler
- Parameters:
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.- Returns:
- ReadOptionsBuilder for chained access.
-
addNonReferenceableClass
- Parameters:
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.- Returns:
- ReadOptionsBuilder for chained access.
-
addPermanentClassFactory(java.lang.Class<?>, com.cedarsoftware.io.JsonReader.ClassFactory)
instead.