Package com.cedarsoftware.io
Class WriteOptionsBuilder
java.lang.Object
com.cedarsoftware.io.WriteOptionsBuilder
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 Classes -
Constructor Summary
ConstructorsConstructorDescriptionStart with default optionsCopy another WriteOptions as a starting point. -
Method Summary
Modifier and TypeMethodDescriptionaddAccessorFactory
(String factoryName, AccessorFactory accessorFactory) Add AccessorFactory to the accessor factories chain.addCustomOption
(String key, Object value) Add a custom option, which may be useful when writing custom writers.addCustomWrittenClass
(Class<?> clazz, JsonWriter.JsonClassWriter customWriter) addCustomWrittenClasses
(Map<? extends Class<?>, ? extends JsonWriter.JsonClassWriter> customWrittenClasses) addExcludedField
(Class<?> clazz, String excludedFieldName) addExcludedFields
(Class<?> clazz, Collection<? extends String> excludedFields) addExcludedFields
(Map<? extends Class<?>, ? extends Collection<? extends String>> excludedFieldNames) addFieldFilter
(String filterName, FieldFilter filter) Add FieldFilter to the field filter chain.addIncludedField
(Class<?> clazz, String includedFieldName) addIncludedFields
(Class<?> clazz, Collection<? extends String> includedFieldNames) addIncludedFields
(Map<? extends Class<?>, ? extends Collection<? extends String>> includedFieldNames) addMethodFilter
(String filterName, MethodFilter methodFilter) Add MethodFilter to the filter chain.addNamedMethodFilter
(String filterName, Class<?> clazz, String methodName) Add a NamedMethodFilter to the filter chain.addNonReferenceableClass
(Class<?> clazz) addNonStandardGetter
(Class<?> c, String fieldName, String methodName) This option permits adding non-standard accessors (used when writing JSON) that access properties from objects, where the method name does not follow a standard setter/getter property name.addNotCustomWrittenClass
(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 writer (that could happen through inheritance).static void
addPermanentAccessorFactory
(String name, AccessorFactory factory) Add an AccessorFactory that is JVM lifecycle scoped.static void
addPermanentAlias
(Class<?> clazz, 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) Call this method to set a permanent (JVM lifetime) allow NaN and Infinity setting.static void
addPermanentBufferSizeMultiplier
(double bufferSizeMultiplier) Sets the permanent buffer size multiplier for all new WriteOptions instances.static void
addPermanentClassLoader
(ClassLoader classLoader) Call this method to set a permanent (JVM lifetime) class loader for JSON serialization.static void
addPermanentCloseStream
(boolean closeStream) Call this method to set a permanent (JVM lifetime) close stream setting.static void
addPermanentEnumPublicFieldsOnly
(boolean enumPublicFieldsOnly) Call this method to set a permanent (JVM lifetime) enum public fields only setting.static void
addPermanentEnumSetWrittenOldWay
(boolean enumSetWrittenOldWay) Call this method to set a permanent (JVM lifetime) enum set written old way setting.static void
addPermanentExcludedField
(Class<?> clazz, String fieldName) Call this method to add a permanent (JVM lifetime) excluded field name of class.static void
addPermanentFieldFilter
(String name, FieldFilter fieldFilter) Add a FieldFilter that is JVM lifecycle scoped.static void
addPermanentForceMapOutputAsTwoArrays
(boolean forceMapOutputAsTwoArrays) Call this method to set a permanent (JVM lifetime) force map output as two arrays setting.static void
addPermanentIndentationSize
(int indentationSize) Sets the permanent indentation size for all new WriteOptions instances.static void
addPermanentIndentationThreshold
(int indentationThreshold) Sets the permanent indentation threshold for all new WriteOptions instances.static void
addPermanentLruSize
(int lruSize) Call this method to set a permanent (JVM lifetime) LRU cache size.static void
addPermanentMaxIndentationDepth
(int maxIndentationDepth) Call this method to set a permanent (JVM lifetime) maximum indentation depth limit for JSON pretty-printing.static void
addPermanentMaxObjectCount
(int maxObjectCount) Call this method to set a permanent (JVM lifetime) maximum object count limit for JSON serialization.static void
addPermanentMaxObjectGraphDepth
(int maxObjectGraphDepth) Call this method to set a permanent (JVM lifetime) maximum object graph depth limit for JSON serialization.static void
addPermanentMaxStringLength
(int maxStringLength) Call this method to set a permanent (JVM lifetime) maximum string length limit for JSON serialization.static void
addPermanentMethodFilter
(String name, MethodFilter methodFilter) Add a MethodFilter that is JVM lifecycle scoped.static void
addPermanentNamedMethodFilter
(String name, Class<?> clazz, String methodName) Add a MethodFilter that is JVM lifecycle scoped.static void
addPermanentNonRef
(Class<?> clazz) Call this method to add a permanent (JVM lifetime) class that should not be treated as referencable when being written out to JSON.static void
addPermanentNonStandardGetter
(Class<?> clazz, String field, String methodName) This option permits adding non-standard getters (used when writing JSON) that access properties from objects, where the method name does not follow a standard setter/getter property name.static void
addPermanentNotCustomWrittenClass
(Class<?> clazz) Call this method to add a permanent (JVM lifetime) class that should not be written with a custom writer when being written out to JSON.static void
addPermanentPrettyPrint
(boolean prettyPrint) Call this method to set a permanent (JVM lifetime) pretty print setting.static void
addPermanentShortMetaKeys
(boolean shortMetaKeys) Call this method to set a permanent (JVM lifetime) short meta keys setting.static void
Call this method to set a permanent (JVM lifetime) type info display setting to always show.static void
Call this method to set a permanent (JVM lifetime) type info display setting to minimal.static void
Call this method to set a permanent (JVM lifetime) type info display setting to never show.static void
addPermanentSkipNullFields
(boolean skipNullFields) Call this method to set a permanent (JVM lifetime) skip null fields setting.static void
addPermanentWriteLongsAsStrings
(boolean writeLongsAsStrings) Call this method to set a permanent (JVM lifetime) write longs as strings setting.static void
addPermanentWriter
(Class<?> clazz, JsonWriter.JsonClassWriter writer) Call this method to add a custom JSON writer to json-io.aliasTypeName
(Class<?> type, String alias) aliasTypeName
(String typeName, String alias) aliasTypeNames
(Map<? extends String, ? extends String> aliases) allowNanAndInfinity
(boolean allowNanAndInfinity) bufferSizeMultiplier
(double bufferSizeMultiplier) build()
Seal the instance of this class so that no more changes can be made to it.classLoader
(ClassLoader loader) closeStream
(boolean closeStream) forceMapOutputAsTwoArrays
(boolean forceMapOutputAsTwoArrays) static WriteOptions
indentationSize
(int indentationSize) indentationThreshold
(int indentationThreshold) Change the date-time format to the ISO date format: "yyyy-MM-ddThh:mm:ss.SSSZ".Change the java.uti.Date and java.sql.Date format output to a "long," the number of seconds since Jan 1, 1970 at midnight.lruSize
(int size) maxIndentationDepth
(int maxIndentationDepth) maxObjectCount
(int maxObjectCount) maxObjectGraphDepth
(int maxObjectGraphDepth) maxStringLength
(int maxStringLength) prettyPrint
(boolean prettyPrint) removeAccessorFactory
(String factoryName) Remove named AccessorFactory from the access factories.removeAliasTypeNamesMatching
(String typeNamePattern) Remove alias entries from this WriteOptionsBuilder instance where the Java fully qualified string class name matches the passed in wildcard pattern.removeFieldFilter
(String filterName) Remove named FieldFilter from the filter chain.removeMethodFilter
(String filterName) Remove named MethodFilter from the method filter chain.static void
Remove a permanently registered AccessorFactory from json-io.static void
removePermanentAliasTypeNamesMatching
(String classNamePattern) Call this method to remove alias patterns from the WriteOptionsBuilder so that when it writes JSON, the classes that match the passed in pattern are not aliased.static void
Remove a permanently registered MethodFilter from json-io.setCustomWrittenClasses
(Map<? extends Class<?>, ? extends JsonWriter.JsonClassWriter> customWrittenClasses) setNotCustomWrittenClasses
(Collection<? extends Class<?>> notCustomClasses) shortMetaKeys
(boolean shortMetaKeys) Set to always show typeSet to show minimal type.Set to never show typeskipNullFields
(boolean skipNullFields) writeEnumAsJsonObject
(boolean writePublicFieldsOnly) Option to write out all the member fields of an enum.Option to write out enums as a String, it will write out the enum.name() field.writeEnumSetOldWay
(boolean writeOldWay) Option to write out all the member fields of an enum.writeLongsAsStrings
(boolean writeLongsAsStrings)
-
Constructor Details
-
WriteOptionsBuilder
public WriteOptionsBuilder()Start with default options -
WriteOptionsBuilder
Copy another WriteOptions as a starting point. If null is passed in, then you get the default options.
-
-
Method Details
-
getDefaultWriteOptions
- Returns:
- Default WriteOptions - no construction needed, unmodifiable.
-
addPermanentAlias
Call this method to add a permanent (JVM lifetime) alias of a class to an often shorter, name. All WriteOptions will automatically be created with any permanent aliases added to them.- Parameters:
clazz
- Class 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 WriteOptionsBuilder so that when it writes JSON, the classes that match the passed in pattern are not aliased. 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.
-
addPermanentExcludedField
Call this method to add a permanent (JVM lifetime) excluded field name of class. All WriteOptions will automatically be created this field field on the excluded list.- Parameters:
clazz
- Class that contains the named field.fieldName
- to be excluded.
-
addPermanentNonRef
Call this method to add a permanent (JVM lifetime) class that should not be treated as referencable when being written out to JSON. This means it will never have an @id nor @ref. This feature is useful for small, immutable classes.- Parameters:
clazz
- Class that will no longer be treated as referenceable when being written to JSON.
-
addPermanentNotCustomWrittenClass
Call this method to add a permanent (JVM lifetime) class that should not be written with a custom writer when being written out to JSON.- Parameters:
clazz
- Class that will no longer be written with a custom writer.
-
addPermanentWriter
Call this method to add a custom JSON writer to json-io. It will associate the Class 'c' to the writer you pass in. The writers are found with isAssignableFrom(). If this is too broad, causing too many classes to be associated to the custom writer, you can indicate that json-io should not use a custom write for a particular class, by calling the addNotCustomWrittenClass() method. This method will add the custom writer such that it will be there permanently, for the life of the JVM (static).- Parameters:
clazz
- Class to assign a custom JSON writer towriter
- The JsonClassWriter which will write the custom JSON format of class.
-
addPermanentNonStandardGetter
This option permits adding non-standard getters (used when writing JSON) that access properties from objects, where the method name does not follow a standard setter/getter property name. For example, on java.time.Instance, to get the 'second' field, the accessor method is 'getEpochSecond()'. Anything added here will automatically be made in all WriteOptions.- Parameters:
clazz
- Class that has the non-standard getter. java.time.Instance in the example above.field
- String name of the class property. 'second' in the example above.methodName
- The name of the non-standard method used to get the field value. 'getEpochSecond' in the example above.
-
addPermanentFieldFilter
Add a FieldFilter that is JVM lifecycle scoped.- Parameters:
fieldFilter
-FieldFilter
class used to eliminate fields from being included in the serialized JSON.
-
addPermanentMethodFilter
Add a MethodFilter that is JVM lifecycle scoped. All WriteOptions instances will contain this filter.- Parameters:
name
- String name of this particular MethodFilter instance.methodFilter
-MethodFilter
class used to eliminate a particular accessor method from being used.
-
removePermanentMethodFilter
Remove a permanently registered MethodFilter from json-io.- Parameters:
name
- String name of the MethodFilter to remove.
-
addPermanentNamedMethodFilter
Add a MethodFilter that is JVM lifecycle scoped. All WriteOptions instances will contain this filter.- Parameters:
name
- String name of this particular method filter instance.clazz
- class that contains the method to be filtered (can be derived class, with field defined on parent class).methodName
- String name of no-argument method to be filtered.
-
addPermanentAccessorFactory
Add an AccessorFactory that is JVM lifecycle scoped. All WriteOptions instances will contain this AccessorFactory. It is the job of an AccessorFactory to provide a possible method name for a particular field. json-io ships with a GetMethodAccessorFactory and an IsMethodAccessFactory. These produce a possible method name for a given field. When a field on a Java class is being accessed (read), and it cannot be obtained directly, then all AccessoryFactory instances will be consulted until an API can be used to read the field.- Parameters:
name
- String name of AccessorFactory. Each factory should have it's own unique name. This will allow these to be defined in a file, later if needed.factory
- AccessorFactory subclass.
-
removePermanentAccessorFactory
Remove a permanently registered AccessorFactory from json-io.- Parameters:
name
- String name of the AccessorFactory to remove.
-
addPermanentMaxIndentationDepth
public static void addPermanentMaxIndentationDepth(int maxIndentationDepth) Call this method to set a permanent (JVM lifetime) maximum indentation depth limit for JSON pretty-printing. All WriteOptions instances will be initialized with this value unless explicitly overridden.- Parameters:
maxIndentationDepth
- int maximum indentation depth allowed during pretty-printing to prevent memory exhaustion. Must be at least 1. Default is 100.
-
addPermanentMaxObjectGraphDepth
public static void addPermanentMaxObjectGraphDepth(int maxObjectGraphDepth) Call this method to set a permanent (JVM lifetime) maximum object graph depth limit for JSON serialization. All WriteOptions instances will be initialized with this value unless explicitly overridden.- Parameters:
maxObjectGraphDepth
- int maximum object graph depth allowed during serialization to prevent stack overflow. Must be at least 1. Default is 10,000.
-
addPermanentMaxObjectCount
public static void addPermanentMaxObjectCount(int maxObjectCount) Call this method to set a permanent (JVM lifetime) maximum object count limit for JSON serialization. All WriteOptions instances will be initialized with this value unless explicitly overridden.- Parameters:
maxObjectCount
- int maximum number of objects allowed during serialization to prevent memory exhaustion. Must be at least 1. Default is 100,000.
-
addPermanentMaxStringLength
public static void addPermanentMaxStringLength(int maxStringLength) Call this method to set a permanent (JVM lifetime) maximum string length limit for JSON serialization. All WriteOptions instances will be initialized with this value unless explicitly overridden.- Parameters:
maxStringLength
- int maximum string length allowed during JSON serialization to prevent memory issues. Must be at least 1. Default is 1,000,000 characters (1MB).
-
addPermanentIndentationSize
public static void addPermanentIndentationSize(int indentationSize) Sets the permanent indentation size for all new WriteOptions instances. This value will be used as the default for all future WriteOptionsBuilder instances.- Parameters:
indentationSize
- int number of spaces per indentation level for pretty-printing. Must be at least 1. Default is 2 spaces.
-
addPermanentBufferSizeMultiplier
public static void addPermanentBufferSizeMultiplier(double bufferSizeMultiplier) Sets the permanent buffer size multiplier for all new WriteOptions instances. This value will be used as the default for all future WriteOptionsBuilder instances.- Parameters:
bufferSizeMultiplier
- double buffer size multiplier for pretty-printing. Must be at least 1.0. Default is 1.3 (30% larger).
-
addPermanentIndentationThreshold
public static void addPermanentIndentationThreshold(int indentationThreshold) Sets the permanent indentation threshold for all new WriteOptions instances. This value will be used as the default for all future WriteOptionsBuilder instances.- Parameters:
indentationThreshold
- int threshold for switching indentation strategies. Must be at least 1. Default is 10.
-
addPermanentClassLoader
Call this method to set a permanent (JVM lifetime) class loader for JSON serialization. All WriteOptions instances will be initialized with this value unless explicitly overridden.- Parameters:
classLoader
- ClassLoader to use when writing JSON to resolve String named classes. Cannot be null. Default is the class loader of WriteOptionsBuilder.
-
addPermanentShortMetaKeys
public static void addPermanentShortMetaKeys(boolean shortMetaKeys) Call this method to set a permanent (JVM lifetime) short meta keys setting. All WriteOptions instances will be initialized with this value unless explicitly overridden.- Parameters:
shortMetaKeys
- boolean true to turn on short meta-keys (@i instead of @id, @r instead of @ref, etc.), false for long. Default is false.
-
addPermanentShowTypeInfoAlways
public static void addPermanentShowTypeInfoAlways()Call this method to set a permanent (JVM lifetime) type info display setting to always show. All WriteOptions instances will be initialized with this value unless explicitly overridden. -
addPermanentShowTypeInfoNever
public static void addPermanentShowTypeInfoNever()Call this method to set a permanent (JVM lifetime) type info display setting to never show. All WriteOptions instances will be initialized with this value unless explicitly overridden. -
addPermanentShowTypeInfoMinimal
public static void addPermanentShowTypeInfoMinimal()Call this method to set a permanent (JVM lifetime) type info display setting to minimal. All WriteOptions instances will be initialized with this value unless explicitly overridden. This is the default setting. -
addPermanentPrettyPrint
public static void addPermanentPrettyPrint(boolean prettyPrint) Call this method to set a permanent (JVM lifetime) pretty print setting. All WriteOptions instances will be initialized with this value unless explicitly overridden.- Parameters:
prettyPrint
- boolean true to turn on pretty-printing (lots of vertical white-space and indentations), false to output JSON in one line. Default is false.
-
addPermanentLruSize
public static void addPermanentLruSize(int lruSize) Call this method to set a permanent (JVM lifetime) LRU cache size. All WriteOptions instances will be initialized with this value unless explicitly overridden.- Parameters:
lruSize
- int size of LRU Cache used to cache Class to Field and Class to Accessor mappings. Must be at least 1. Default is 1000.
-
addPermanentWriteLongsAsStrings
public static void addPermanentWriteLongsAsStrings(boolean writeLongsAsStrings) Call this method to set a permanent (JVM lifetime) write longs as strings setting. All WriteOptions instances will be initialized with this value unless explicitly overridden.- Parameters:
writeLongsAsStrings
- boolean true to write longs as Strings, false to write them as native JSON longs. Writing longs as Strings fixes precision errors in Javascript. Default is false.
-
addPermanentSkipNullFields
public static void addPermanentSkipNullFields(boolean skipNullFields) Call this method to set a permanent (JVM lifetime) skip null fields setting. All WriteOptions instances will be initialized with this value unless explicitly overridden.- Parameters:
skipNullFields
- boolean true indicates fields with null values will not be written, false will still output the field with an associated null value. Default is false.
-
addPermanentForceMapOutputAsTwoArrays
public static void addPermanentForceMapOutputAsTwoArrays(boolean forceMapOutputAsTwoArrays) Call this method to set a permanent (JVM lifetime) force map output as two arrays setting. All WriteOptions instances will be initialized with this value unless explicitly overridden.- Parameters:
forceMapOutputAsTwoArrays
- boolean true will force Java Maps to be written as two parallel arrays, false will write as one JSON object if all keys are Strings. Default is false.
-
addPermanentAllowNanAndInfinity
public static void addPermanentAllowNanAndInfinity(boolean allowNanAndInfinity) Call this method to set a permanent (JVM lifetime) allow NaN and Infinity setting. All WriteOptions instances will be initialized with this value unless explicitly overridden.- Parameters:
allowNanAndInfinity
- boolean true will allow Double and Floats to be output as NAN and INFINITY, false and these values will come across as null. Default is false.
-
addPermanentEnumPublicFieldsOnly
public static void addPermanentEnumPublicFieldsOnly(boolean enumPublicFieldsOnly) Call this method to set a permanent (JVM lifetime) enum public fields only setting. All WriteOptions instances will be initialized with this value unless explicitly overridden.- Parameters:
enumPublicFieldsOnly
- boolean true indicates only public fields will be output on an Enum, false will include all fields. Default is false.
-
addPermanentEnumSetWrittenOldWay
public static void addPermanentEnumSetWrittenOldWay(boolean enumSetWrittenOldWay) Call this method to set a permanent (JVM lifetime) enum set written old way setting. All WriteOptions instances will be initialized with this value unless explicitly overridden.- Parameters:
enumSetWrittenOldWay
- boolean true indicates EnumSet instances are written with @enum instead of @type. Default is true for backward compatibility.
-
addPermanentCloseStream
public static void addPermanentCloseStream(boolean closeStream) Call this method to set a permanent (JVM lifetime) close stream setting. All WriteOptions instances will be initialized with this value unless explicitly overridden.- Parameters:
closeStream
- boolean true if the OutputStream should be closed when writing is finished, false to leave it open for continued writing. Default is true.
-
classLoader
- Parameters:
loader
- ClassLoader to use when writing JSON to resolve String named classes.- Returns:
- WriteOptionsBuilder for chained access.
-
shortMetaKeys
- Parameters:
shortMetaKeys
- boolean true to turn on short meta-keys, false for long.- Returns:
- WriteOptionsBuilder for chained access.
-
aliasTypeNames
- Parameters:
aliases
- Map containing String class names to alias names. The passed in Map will be copied, and be the new baseline settings.- Returns:
- WriteOptionsBuilder for chained access.
-
aliasTypeName
- Parameters:
type
- Class to aliasalias
- String shorter name to use, typically.- Returns:
- WriteOptionsBuilder for chained access.
-
aliasTypeName
- Parameters:
typeName
- String class namealias
- String shorter name to use, typically.- Returns:
- WriteOptionsBuilder for chained access.
-
removeAliasTypeNamesMatching
Remove alias entries from this WriteOptionsBuilder 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:
- WriteOptionsBuilder for chained access.
-
showTypeInfoAlways
Set to always show type- Returns:
- WriteOptionsBuilder for chained access.
-
showTypeInfoNever
Set to never show type- Returns:
- WriteOptionsBuilder for chained access.
-
showTypeInfoMinimal
Set to show minimal type. This means that when the type of object can be inferred, a type field will not be output. A Field that points to an instance of the same time, or a typed [] of objects don't need the type info. However, an Object[], a Collection with no generics, the reader will need to know what type the JSON object is, in order to instantiate the write Java class to which the information will be copied.- Returns:
- WriteOptionsBuilder for chained access.
-
prettyPrint
- Parameters:
prettyPrint
- boolean 'prettyPrint' setting, true to turn on, false will turn off.- Returns:
- WriteOptionsBuilder for chained access.
-
lruSize
- Parameters:
size
- Max size of the cache for Class fields and Class accessors- Returns:
- WriteOptionsBuilder for chained access.
-
writeLongsAsStrings
- Parameters:
writeLongsAsStrings
- boolean true to turn on writing longs as Strings, false to write them as native JSON longs.- Returns:
- WriteOptionsBuilder for chained access.
-
skipNullFields
- Parameters:
skipNullFields
- boolean setting, where true indicates fields with null values will not be written to the JSON, false will allow the field to still be written.- Returns:
- WriteOptionsBuilder for chained access.
-
forceMapOutputAsTwoArrays
- Parameters:
forceMapOutputAsTwoArrays
- boolean 'forceMapOutputAsTwoArrays' setting. true will force Java Maps to be written out as two parallel arrays, once for keys, one array for values. false will write out one JSON { } object, if all keys are Strings. If not, then the Map will be output as two parallel arrays (@keys:[...], @values:[...]).- Returns:
- WriteOptionsBuilder for chained access.
-
allowNanAndInfinity
- Parameters:
allowNanAndInfinity
- boolean 'allowNanAndInfinity' setting. true will allow Double and Floats to be output as NAN and INFINITY, false and these values will come across as null.- Returns:
- WriteOptionsBuilder for chained access.
-
writeEnumsAsString
Option to write out enums as a String, it will write out the enum.name() field. This is the default way enums will be written out.- Returns:
- WriteOptionsBuilder for chained access.
-
writeEnumAsJsonObject
Option to write out all the member fields of an enum. You can also filter the field to write out only the public fields on the enum.- Parameters:
writePublicFieldsOnly
- boolean, only write out the public fields when writing enums as objects. Defaults to false.- Returns:
- WriteOptionsBuilder for chained access.
-
writeEnumSetOldWay
Option to write out all the member fields of an enum. You can also filter the field to write out only the public fields on the enum.- Parameters:
writeOldWay
- boolean, write EnumSet using @enum instead of @type.- Returns:
- WriteOptionsBuilder for chained access.
-
closeStream
- Parameters:
closeStream
- boolean set to 'true' to have JsonIo close the OutputStream when it is finished writing to it. The default is 'true'. If false, the OutputStream will not be closed, allowing you to continue writing further. Example, NDJSON that has new line eliminated JSON objects repeated.- Returns:
- WriteOptionsBuilder for chained access.
-
setCustomWrittenClasses
public WriteOptionsBuilder setCustomWrittenClasses(Map<? extends Class<?>, ? extends JsonWriter.JsonClassWriter> customWrittenClasses) - Parameters:
customWrittenClasses
- Map of Class to JsonWriter.JsonClassWriter. Establish the passed in Map as the established Map of custom writers to be used when writing JSON. Using this method more than once, will set the custom writers to only the values from the Set in the last call made.- Returns:
- WriteOptionsBuilder for chained access.
-
addCustomWrittenClasses
public WriteOptionsBuilder addCustomWrittenClasses(Map<? extends Class<?>, ? extends JsonWriter.JsonClassWriter> customWrittenClasses) - Parameters:
customWrittenClasses
- Map of Class to JsonWriter.JsonClassWriter. Adds all custom writers into the custom writers map.- Returns:
- WriteOptionsBuilder for chained access.
-
addCustomWrittenClass
public WriteOptionsBuilder addCustomWrittenClass(Class<?> clazz, JsonWriter.JsonClassWriter customWriter) - Parameters:
clazz
- Class to add a custom writer for.customWriter
- JsonClassWriter to use when the passed in Class is encountered during serialization.- Returns:
- WriteOptionsBuilder for chained access.
-
addNotCustomWrittenClass
Add a class to the not-customized list - the list of classes that you do not want to be picked up by a custom writer (that could happen through inheritance).- Parameters:
notCustomClass
- Class to add to the not-customized list.- Returns:
- WriteOptionsBuilder for chained access.
-
setNotCustomWrittenClasses
public WriteOptionsBuilder setNotCustomWrittenClasses(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:
- WriteOptionsBuilder for chained access.
-
addIncludedField
- Parameters:
clazz
- Class to add a single field to be included in the written JSON.includedFieldName
- String name of field to include in written JSON.- Returns:
- WriteOptionsBuilder for chained access.
-
addIncludedFields
public WriteOptionsBuilder addIncludedFields(Class<?> clazz, Collection<? extends String> includedFieldNames) - Parameters:
clazz
- Class to add a Collection of fields to be included in written JSON.includedFieldNames
- Collection of String name of fields to include in written JSON.- Returns:
- WriteOptionsBuilder for chained access.
-
addIncludedFields
public WriteOptionsBuilder addIncludedFields(Map<? extends Class<?>, ? extends Collection<? extends String>> includedFieldNames) - Parameters:
includedFieldNames
- Map of Class's mapped to Collection of String field names to include in the written JSON.- Returns:
- WriteOptionsBuilder for chained access.
-
addExcludedField
- Parameters:
clazz
- Class to add a single field to be excluded.excludedFieldName
- String name of field to exclude from written JSON.- Returns:
- WriteOptionsBuilder for chained access.
-
addExcludedFields
public WriteOptionsBuilder addExcludedFields(Class<?> clazz, Collection<? extends String> excludedFields) - Parameters:
clazz
- Class to add a Collection of fields to be excluded in written JSON.excludedFields
- Collection of String name of fields to exclude in written JSON.- Returns:
- WriteOptionsBuilder for chained access.
-
addExcludedFields
public WriteOptionsBuilder addExcludedFields(Map<? extends Class<?>, ? extends Collection<? extends String>> excludedFieldNames) - Parameters:
excludedFieldNames
- Map of Class's mapped to Collection of String field names to exclude from written JSON.- Returns:
- WriteOptionsBuilder for chained access.
-
isoDateFormat
Change the date-time format to the ISO date format: "yyyy-MM-ddThh:mm:ss.SSSZ". This is for java.util.Date and java.sql.Date. The fractional sections are omitted if millis are 0.- Returns:
- WriteOptionsBuilder for chained access.
-
longDateFormat
Change the java.uti.Date and java.sql.Date format output to a "long," the number of seconds since Jan 1, 1970 at midnight. Useful if you do not need to see the JSON, and want to keep the format smaller. This is for java.util.Date and java.sql.Date.- Returns:
- WriteOptionsBuilder for chained access.
-
addNonStandardGetter
This option permits adding non-standard accessors (used when writing JSON) that access properties from objects, where the method name does not follow a standard setter/getter property name. For example, on java.time.Instance, to get the 'second' field, the accessor method is 'getEpochSecond()'.- Parameters:
c
- Class that has the non-standard accessor. java.time.Instance in the example above.fieldName
- String name of the class property. 'second' in the example above.methodName
- The name of the non-standard method used to get the field value. 'getEpochSecond' in the example above.- Returns:
- WriteOptionsBuilder 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:
- WriteOptionsBuilder for chained access.
-
addCustomOption
Add a custom option, which may be useful when writing custom writers. To remove a custom option, add the option with the appropriate key and null as the value.- Parameters:
key
- String name of the custom optionvalue
- Object value of the custom option- Returns:
- WriteOptionsBuilder for chained access.
-
addFieldFilter
Add FieldFilter to the field filter chain. FieldFilters are presented a chance to eliminate a field by returning true from its boolean filter() method. If any FieldFilter returns true, the field is excluded.- Parameters:
filterName
- String name of filterfilter
- FieldFilter to add- Returns:
- WriteOptionsBuilder for chained access.
-
removeFieldFilter
Remove named FieldFilter from the filter chain.- Parameters:
filterName
- String name of FieldFilter to delete- Returns:
- WriteOptionsBuilder for chained access.
-
addMethodFilter
Add MethodFilter to the filter chain. MethodFilters are presented a chance to eliminate a "getter" type accessing method by returning true from the boolean filter() method. If any MethodFilter returns true, the accessor method is excluded. This means it will drop back to use field access (attempting to access private field in same module with setAccessible()). This API is used when you want to write your own implementation of a MethodFilter.- Parameters:
filterName
- String name of filtermethodFilter
-MethodFilter
to add- Returns:
WriteOptionsBuilder
for chained access.
-
addNamedMethodFilter
public WriteOptionsBuilder addNamedMethodFilter(String filterName, Class<?> clazz, String methodName) Add a NamedMethodFilter to the filter chain. NamedMethodFilters are presented a chance to eliminate a "getter" type accessing method by returning true from the boolean filter() method. If the NamedMethodFilter matches a class and accessor method name, and it has no args, is public, and non-static, the accessor method is excluded. This means it will drop back to use field access (attempting to access private field in same module with setAccessible()).- Parameters:
filterName
- String name of filterclazz
- Class containing method to filtermethodName
- String name of method to not use for accessing value.- Returns:
WriteOptionsBuilder
for chained access.
-
removeMethodFilter
Remove named MethodFilter from the method filter chain.- Parameters:
filterName
- String name of filter- Returns:
WriteOptionsBuilder
for chained access.
-
addAccessorFactory
Add AccessorFactory to the accessor factories chain. AccessFactories permit adding a standard pattern of locating "read" methods, for example, there is a built-in "get" and "is" AccessoryFactory.- Parameters:
factoryName
- String name of accessor factoryaccessorFactory
-AccessorFactory
to add- Returns:
WriteOptionsBuilder
for chained access.
-
removeAccessorFactory
Remove named AccessorFactory from the access factories.- Parameters:
factoryName
- String name of accessor filter- Returns:
WriteOptionsBuilder
for chained access.
-
maxIndentationDepth
- Parameters:
maxIndentationDepth
- int maximum indentation depth allowed during pretty-printing. Default is 100 levels. This prevents excessive memory usage from deeply nested indentations.- Returns:
- WriteOptionsBuilder for chained access.
-
maxObjectGraphDepth
- Parameters:
maxObjectGraphDepth
- int maximum object graph depth allowed during serialization. Default is 10,000 levels. This prevents excessive recursion from deeply nested object structures.- Returns:
- WriteOptionsBuilder for chained access.
-
maxObjectCount
- Parameters:
maxObjectCount
- int maximum number of objects allowed during serialization. Default is 100,000 objects. This prevents unbounded memory growth during large object graph processing.- Returns:
- WriteOptionsBuilder for chained access.
-
maxStringLength
- Parameters:
maxStringLength
- int maximum string length allowed during JSON serialization. Default is 1,000,000 characters (1MB). This prevents excessive memory allocation for very large strings.- Returns:
- WriteOptionsBuilder for chained access.
-
indentationSize
- Parameters:
indentationSize
- int number of spaces per indentation level for pretty-printing. Default is 2 spaces. Must be at least 1.- Returns:
- WriteOptionsBuilder for chained access.
-
bufferSizeMultiplier
- Parameters:
bufferSizeMultiplier
- double buffer size multiplier for pretty-printing. Default is 1.3 (30% larger). Must be at least 1.0.- Returns:
- WriteOptionsBuilder for chained access.
-
indentationThreshold
- Parameters:
indentationThreshold
- int threshold for switching indentation strategies. Default is 10. Must be at least 1.- Returns:
- WriteOptionsBuilder for chained access.
-
build
Seal the instance of this class so that no more changes can be made to it.- Returns:
- WriteOptionsBuilder for chained access.
-