Package com.cedarsoftware.io
Interface ReadOptions
public interface ReadOptions
This class contains all the "feature" control (options) for controlling json-io's
flexibility in reading JSON. An instance of this class is passed to the JsonReader.toJson() APIs
to set the desired features.
You can make this class immutable and then store the class for re-use. Call the ".build()" method and then no longer can any methods that change state be called - it will throw a JsonIoException.
This class can be created from another ReadOptions instance, using the "copy constructor" that takes a ReadOptions. All properties of the other ReadOptions will be copied to the new instance, except for the 'built' property. That always starts off as false (mutable) so that you can make changes to options.
You can make this class immutable and then store the class for re-use. Call the ".build()" method and then no longer can any methods that change state be called - it will throw a JsonIoException.
This class can be created from another ReadOptions instance, using the "copy constructor" that takes a ReadOptions. All properties of the other ReadOptions will be copied to the new instance, except for the 'built' property. That always starts off as false (mutable) so that you can make changes to options.
- 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
Modifier and TypeInterfaceDescriptionstatic enum
static enum
static enum
-
Method Summary
Modifier and TypeMethodDescriptionvoid
getClassFactory
(Class<?> c) Get the ClassFactory associated to the passed in class.Class<?>
getCoercedClass
(Class<?> c) Fetch the coerced class for the passed in fully qualified class name.com.cedarsoftware.util.convert.ConverterOptions
getCustomOption
(String key) Get a custom optiongetCustomReader
(Class<?> c) Fetch the custom reader for the passed in Class.getDeepDeclaredFields
(Class<?> c) Gets the declared fields for the full class hierarchy of a given classgetDeepInjectorMap
(Class<?> classToTraverse) int
int
getTypeNameAlias
(String typeName) Alias Type Names, e.g.Class<?>
boolean
boolean
isClassCoerced
(String className) boolean
boolean
isCustomReaderClass
(Class<?> clazz) boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
isNonReferenceableClass
(Class<?> clazz) boolean
isNotCustomReaderClass
(Class<?> clazz) boolean
boolean
-
Method Details
-
isFloatingPointDouble
boolean isFloatingPointDouble()- Returns:
- true if floating point values should always be returned as Doubles. This is the default.
-
isFloatingPointBigDecimal
boolean isFloatingPointBigDecimal()- Returns:
- true if floating point values should always be returned as BigDecimals.
-
isFloatingPointBoth
boolean isFloatingPointBoth()- Returns:
- true if floating point values should always be returned dynamically, as Double or BigDecimal, favoring Double except when precision would be lost, then BigDecimal is returned.
-
isIntegerTypeLong
boolean isIntegerTypeLong()- Returns:
- true if integer values should always be returned as Longs. This is the default.
-
isIntegerTypeBigInteger
boolean isIntegerTypeBigInteger()- Returns:
- true if integer values should always be returned as BigIntegers.
-
isIntegerTypeBoth
boolean isIntegerTypeBoth()- Returns:
- true if integer values should always be returned dynamically, as Long or BigInteger, favoring Long except when precision would be lost, then BigInteger is returned.
-
isAllowNanAndInfinity
boolean isAllowNanAndInfinity() -
getClassLoader
ClassLoader getClassLoader()- Returns:
- ClassLoader to be used when reading JSON to resolve String named classes.
-
isFailOnUnknownType
boolean isFailOnUnknownType()- Returns:
- boolean true if an 'unknownTypeClass' is set, false if it is not sell (null).
-
getUnknownTypeClass
Class<?> getUnknownTypeClass()- Returns:
- the Class which will have unknown fields set upon it. Typically this is a Map derivative.
-
isCloseStream
boolean isCloseStream()- Returns:
- boolean 'true' if the InputStream should be closed when the reading is finished. The default is 'true.'
-
getMaxDepth
int getMaxDepth()- Returns:
- int maximum level the JSON can be nested. Once the parsing nesting level reaches this depth, a JsonIoException will be thrown instead of a StackOverflowException. Prevents security risk from StackOverflow attack vectors.
-
getLruSize
int getLruSize()- Returns:
- int size of LRU Cache used to cache Class to Field and Class to injectors
-
getTypeNameAlias
Alias Type Names, e.g. "ArrayList" instead of "java.util.ArrayList".- Parameters:
typeName
- String name of type to fetch alias for. There are no default aliases.- Returns:
- String alias name or null if type name is not aliased.
-
isClassCoerced
- Returns:
- boolean true if the passed in Class name is being coerced to another type, false otherwise.
-
getCoercedClass
Fetch the coerced class for the passed in fully qualified class name.- Parameters:
c
- Class to coerce- Returns:
- Class destination (coerced) class or null if there is none.
-
getMissingFieldHandler
JsonReader.MissingFieldHandler getMissingFieldHandler()- Returns:
- JsonReader.MissingFieldHandler to be called when a field in the JSON is read in, yet there is no corresponding field on the destination object to receive the field value.
-
isNonReferenceableClass
- Parameters:
clazz
- Class to check to see if it is non-referenceable. Non-referenceable classes will always create a new instance when read in and never use @id/@ref. This uses more memory when the JSON is read in, as there will be a separate instance in memory for each occurrence. There are certain classes that json-io automatically treats as non-referenceable, like Strings, Enums, Class, and any Number instance (BigDecimal, AtomicLong, etc.) You can add to this list. Often, non-referenceable classes are useful for classes that can be defined in one line as a JSON, like a LocalDateTime, for example.- Returns:
- boolean true if the passed in class is considered a non-referenceable class.
-
isNotCustomReaderClass
- Parameters:
clazz
- Class to see if it is on the not-customized list. Classes are added to this list when a class is being picked up through inheritance, and you don't want it to have a custom reader associated to it.- Returns:
- boolean true if the passed in class is on the not-customized list, false otherwise.
-
isCustomReaderClass
- Parameters:
clazz
- Class to check to see if there is a custom reader associated to it.- Returns:
- boolean true if there is an associated custom reader class associated to the passed in class, false otherwise.
-
getClassFactory
Get the ClassFactory associated to the passed in class.- Parameters:
c
- Class for which to fetch the ClassFactory.- Returns:
- JsonReader.ClassFactory instance associated to the passed in class.
-
getCustomReader
Fetch the custom reader for the passed in Class. If it is cached (already associated to the passed in Class), return the same instance, otherwise, make a call to get the custom reader and store that result.- Parameters:
c
- Class of object for which fetch a custom reader- Returns:
- JsonClassReader for the custom class (if one exists), null otherwise.
-
isReturningJsonObjects
boolean isReturningJsonObjects()- Returns:
- true if returning items in basic JSON object format
-
isReturningJavaObjects
boolean isReturningJavaObjects()- Returns:
- true if returning items in full Java object formats. Useful for accurate reproduction of graphs into the orginal types such as when cloning objects.
-
getDeepInjectorMap
-
clearCaches
void clearCaches() -
getDeepDeclaredFields
Gets the declared fields for the full class hierarchy of a given class- Parameters:
c
- - given class.- Returns:
- Map - map of string fieldName to Field Object. This will have the deep list of fields for a given class.
-
getConverterOptions
com.cedarsoftware.util.convert.ConverterOptions getConverterOptions() -
getCustomOption
Get a custom option- Parameters:
key
- String name of the custom option- Returns:
- Object value of the custom option
-