public class WriteOptions extends Object
Modifier and Type | Class and Description |
---|---|
static class |
WriteOptions.ShowType |
Modifier and Type | Field and Description |
---|---|
static String |
ISO_DATE_FORMAT |
static String |
ISO_DATE_TIME_FORMAT |
Constructor and Description |
---|
WriteOptions()
Start with default options
|
WriteOptions(WriteOptions other)
Copy all the settings from the passed in 'other' WriteOptions
|
Modifier and Type | Method and Description |
---|---|
WriteOptions |
addCustomWrittenClass(Class<?> clazz,
JsonWriter.JsonClassWriter customWriter) |
WriteOptions |
addExcludedField(Class<?> clazz,
String excludedField) |
WriteOptions |
addExcludedFields(Class<?> clazz,
Collection<String> excludedFields) |
WriteOptions |
addExcludedFields(Map<Class<?>,Collection<String>> excludedFields) |
WriteOptions |
addIncludedField(Class<?> clazz,
String includedField) |
WriteOptions |
addIncludedFields(Class<?> clazz,
Collection<String> includedFields) |
WriteOptions |
addIncludedFields(Map<Class<?>,Collection<String>> includedFields) |
WriteOptions |
addNonReferenceableClass(Class<?> clazz) |
WriteOptions |
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).
|
WriteOptions |
aliasTypeName(String typeName,
String alias) |
Map<String,String> |
aliasTypeNames() |
WriteOptions |
aliasTypeNames(Map<String,String> aliasTypeNames) |
WriteOptions |
allowNanAndInfinity(boolean allowNanAndInfinity) |
WriteOptions |
build()
Seal the instance of this class so that no more changes can be made to it.
|
WriteOptions |
classLoader(ClassLoader classLoader) |
WriteOptions |
dateTimeFormat(String format)
Change the date-time format to the passed in format.
|
WriteOptions |
forceMapOutputAsTwoArrays(boolean forceMapOutputAsTwoArrays) |
ClassLoader |
getClassLoader() |
JsonWriter.JsonClassWriter |
getCustomWriter(Class<?> c)
Fetch the custom writer for the passed in Class.
|
Map<Class<?>,JsonWriter.JsonClassWriter> |
getCustomWrittenClasses() |
Set<Accessor> |
getExcludedAccessors(Class<?> clazz)
Get the list of Accessors associated to the passed in class that are to be excluded in the written JSON.
|
Collection<Accessor> |
getExcludedAccessorsForClass(Class<?> c) |
Set<String> |
getExcludedFields(Class<?> clazz)
Get the list of fields associated to the passed in class that are to be excluded in the written JSON.
|
Map<Class<?>,Set<String>> |
getExcludedFieldsPerAllClasses() |
Set<Accessor> |
getIncludedAccessors(Class<?> clazz)
Get the list of Accessors associated to the passed in class that are to be included in the written JSON.
|
Collection<Accessor> |
getIncludedAccessorsForClass(Class<?> c) |
Map<Class<?>,Set<Accessor>> |
getIncludedAccessorsPerAllClasses() |
Set<String> |
getIncludedFields(Class<?> clazz)
Get the list of fields associated to the passed in class that are to be included in the written JSON.
|
Map<Class<?>,Set<String>> |
getIncludedFieldsPerAllClasses() |
Collection<Class<?>> |
getNonReferenceableClasses() |
Set<Class<?>> |
getNotCustomWrittenClasses() |
String |
getTypeNameAlias(String typeName)
Alias Type Names, e.g.
|
boolean |
isAllowNanAndInfinity() |
boolean |
isAlwaysShowingType() |
boolean |
isBuilt() |
boolean |
isCustomWrittenClass(Class<?> clazz) |
boolean |
isEnumPublicFieldsOnly()
true indicates that only public fields will be output on an Enum.
|
boolean |
isForceMapOutputAsTwoArrays() |
boolean |
isLongDateFormat() |
boolean |
isMinimalShowingType() |
boolean |
isNeverShowingType() |
boolean |
isNonReferenceableClass(Class<?> clazz) |
boolean |
isNotCustomWrittenClass(Class<?> clazz) |
WriteOptions |
isoDateFormat()
Change the date-time format to the ISO date format: "yyyy-MM-dd".
|
WriteOptions |
isoDateTimeFormat()
Change the date-time format to the ISO date-time format: "yyyy-MM-dd'T'HH:mm:ss" (default).
|
boolean |
isPrettyPrint() |
boolean |
isShortMetaKeys() |
boolean |
isSkipNullFields() |
boolean |
isWriteEnumAsString() |
boolean |
isWriteLongsAsStrings() |
WriteOptions |
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.
|
WriteOptions |
prettyPrint(boolean prettyPrint) |
WriteOptions |
setCustomWrittenClasses(Map<Class<?>,JsonWriter.JsonClassWriter> customWrittenClasses) |
WriteOptions |
setNotCustomWrittenClasses(Collection<Class<?>> notCustomClasses) |
WriteOptions |
shortMetaKeys(boolean shortMetaKeys) |
WriteOptions |
showTypeInfoAlways()
Set to always show type
|
WriteOptions |
showTypeInfoMinimal()
Set to show minimal type.
|
WriteOptions |
showTypeInfoNever()
Set to never show type
|
WriteOptions |
skipNullFields(boolean skipNullFields) |
WriteOptions |
writeEnumAsJsonObject(boolean writePublicFieldsOnly)
Option to write out all the member fields of an enum.
|
WriteOptions |
writeEnumsAsString()
Option to write out enums as a String, it will write out the enum.name() field.
|
WriteOptions |
writeLongsAsStrings(boolean writeLongsAsStrings) |
public static final String ISO_DATE_FORMAT
public static final String ISO_DATE_TIME_FORMAT
public WriteOptions()
public WriteOptions(WriteOptions other)
other
- WriteOptions - source to copy from.public ClassLoader getClassLoader()
public WriteOptions classLoader(ClassLoader classLoader)
classLoader
- ClassLoader to use when writing JSON to resolve String named classes.public boolean isShortMetaKeys()
public WriteOptions shortMetaKeys(boolean shortMetaKeys)
shortMetaKeys
- boolean true to turn on short meta-keys, false for long.public String getTypeNameAlias(String typeName)
typeName
- String name of type to fetch alias for. There are no default aliases.public Map<String,String> aliasTypeNames()
public WriteOptions 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 WriteOptions aliasTypeName(String typeName, String alias)
typeName
- String class namealias
- String shorter name to use, typically.public boolean isAlwaysShowingType()
public boolean isNeverShowingType()
public boolean isMinimalShowingType()
public WriteOptions showTypeInfoAlways()
public WriteOptions showTypeInfoNever()
public WriteOptions showTypeInfoMinimal()
public boolean isPrettyPrint()
public WriteOptions prettyPrint(boolean prettyPrint)
prettyPrint
- boolean 'prettyPrint' setting, true to turn on, false will turn off.public boolean isWriteLongsAsStrings()
public WriteOptions writeLongsAsStrings(boolean writeLongsAsStrings)
writeLongsAsStrings
- boolean true to turn on writing longs as Strings, false to write them as
native JSON longs.public boolean isSkipNullFields()
public WriteOptions skipNullFields(boolean skipNullFields)
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.public boolean isForceMapOutputAsTwoArrays()
public WriteOptions forceMapOutputAsTwoArrays(boolean forceMapOutputAsTwoArrays)
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:[...]).public boolean isAllowNanAndInfinity()
public WriteOptions allowNanAndInfinity(boolean allowNanAndInfinity)
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.public boolean isWriteEnumAsString()
public boolean isEnumPublicFieldsOnly()
public WriteOptions writeEnumsAsString()
public WriteOptions writeEnumAsJsonObject(boolean writePublicFieldsOnly)
writePublicFieldsOnly
- boolean, only write out the public fields when writing enums as objectspublic WriteOptions setCustomWrittenClasses(Map<Class<?>,JsonWriter.JsonClassWriter> customWrittenClasses)
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.public WriteOptions addCustomWrittenClass(Class<?> clazz, JsonWriter.JsonClassWriter customWriter)
clazz
- Class to add a custom writer for.customWriter
- JsonClassWriter to use when the passed in Class is encountered during serialization.public Map<Class<?>,JsonWriter.JsonClassWriter> getCustomWrittenClasses()
public boolean isCustomWrittenClass(Class<?> clazz)
clazz
- Class to check to see if there is a custom writer associated to it.public boolean isNotCustomWrittenClass(Class<?> clazz)
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
writer associated to it.public Set<Class<?>> getNotCustomWrittenClasses()
public WriteOptions addNotCustomWrittenClass(Class<?> notCustomClass)
notCustomClass
- Class to add to the not-customized list.public WriteOptions setNotCustomWrittenClasses(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 Set<String> getIncludedFields(Class<?> clazz)
clazz
- Class for which the fields to be included in JSON output will be returned.public Set<Accessor> getIncludedAccessors(Class<?> clazz)
clazz
- Class for which the Accessors to be included in JSON output will be returned.public Map<Class<?>,Set<String>> getIncludedFieldsPerAllClasses()
public Map<Class<?>,Set<Accessor>> getIncludedAccessorsPerAllClasses()
public WriteOptions addIncludedField(Class<?> clazz, String includedField)
clazz
- Class to add a single field to be included in the written JSON.includedField
- String name of field to include in written JSON.public WriteOptions addIncludedFields(Class<?> clazz, Collection<String> includedFields)
clazz
- Class to add a Collection of fields to be included in written JSON.includedFields
- Collection of String name of fields to include in written JSON.public WriteOptions addIncludedFields(Map<Class<?>,Collection<String>> includedFields)
includedFields
- Map of Class's mapped to Collection of String field names to include in the written JSON.public WriteOptions addExcludedField(Class<?> clazz, String excludedField)
clazz
- Class to add a single field to be excluded.excludedField
- String name of field to exclude from written JSON.public WriteOptions addExcludedFields(Class<?> clazz, Collection<String> excludedFields)
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.public WriteOptions addExcludedFields(Map<Class<?>,Collection<String>> excludedFields)
excludedFields
- Map of Class's mapped to Collection of String field names to exclude from written JSON.public Set<String> getExcludedFields(Class<?> clazz)
clazz
- Class for which the fields to be excluded in JSON output will be returned.public Map<Class<?>,Set<String>> getExcludedFieldsPerAllClasses()
public Set<Accessor> getExcludedAccessors(Class<?> clazz)
clazz
- Class for which the Accessors to be excluded in JSON output will be returned.public Collection<Accessor> getIncludedAccessorsForClass(Class<?> c)
public Collection<Accessor> getExcludedAccessorsForClass(Class<?> c)
public WriteOptions isoDateFormat()
public WriteOptions isoDateTimeFormat()
public WriteOptions longDateFormat()
public boolean isLongDateFormat()
public WriteOptions dateTimeFormat(String format)
public boolean isNonReferenceableClass(Class<?> clazz)
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.public Collection<Class<?>> getNonReferenceableClasses()
public WriteOptions 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.public WriteOptions build()
public boolean isBuilt()
public JsonWriter.JsonClassWriter getCustomWriter(Class<?> c)
c
- Class of object for which fetch a custom writerCopyright © 2023. All rights reserved.