Interface WriteOptions

All Known Implementing Classes:
WriteOptionsBuilder.DefaultWriteOptions

public interface WriteOptions
This class contains all the "feature" control (options) for controlling json-io's output JSON. An instance of this class is passed to the JsonWriter.toJson() APIs to set the desired capabilities.

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 WriteOptions instance, using the "copy constructor" that takes a WriteOptions. All properties of the other WriteOptions 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.
  • Method Details

    • isPrettyPrint

      boolean isPrettyPrint()
      Returns:
      boolean 'prettyPrint' setting, true being yes, pretty-print mode using lots of vertical white-space and indentations, 'false' will output JSON in one line. The default is false.
    • isWriteLongsAsStrings

      boolean isWriteLongsAsStrings()
      Returns:
      boolean 'writeLongsAsStrings' setting, true indicating longs will be written as Strings, false to write them out as native JSON longs. Writing Strings as Longs to the JSON, will fix errors in Javascript when an 18-19 digit long value is sent to Javascript. This is because Javascript stores them in Doubles, which cannot handle the precision of an 18-19 digit long, but a String will retain the full value into Javascript. The default is false.
    • isSkipNullFields

      boolean isSkipNullFields()
      Returns:
      boolean skipNullFields setting, true indicates fields with null values will not be written, false will still output the field with an associated null value. false is the default.
    • isForceMapOutputAsTwoArrays

      boolean isForceMapOutputAsTwoArrays()
      Returns:
      boolean 'forceMapOutputAsTwoArrays' setting. true indicates that two arrays will be written to represent a Java Map, one for keys, one for values. false indicates one Java object will be used, if all the keys of the Map are Strings. If not, then the Map will be written out with a key array, and a parallel value array. (@keys:[...], @values:[...]). false is the default.
    • isAllowNanAndInfinity

      boolean isAllowNanAndInfinity()
      Returns:
      boolean will return true if NAN and Infinity are allowed to be written out for Doubles and Floats, else null will be written out..
    • isEnumPublicFieldsOnly

      boolean isEnumPublicFieldsOnly()
      true indicates that only public fields will be output on an Enum. Enums don't often have fields added to them but if so, then only the public fields will be written. The Enum will be written out in JSON object { } format. If there are not added fields to an Enum, it will be written out as a single line value. The default value is true. If you set this to false, it will change the 'enumFieldsAsObject' to true - because you will be showing potentially more than one value, it will require the enum to be written as an object.
    • isCloseStream

      boolean isCloseStream()
      Returns:
      boolean 'true' if the OutputStream should be closed when the reading is finished. The default is 'true.'
    • getClassLoader

      ClassLoader getClassLoader()
      Returns:
      ClassLoader to be used when writing JSON to resolve String named classes.
    • isShortMetaKeys

      boolean isShortMetaKeys()
      Returns:
      boolean true if showing short meta-keys (@i instead of @id, @ instead of @ref, @t instead of @type, @k instead of @keys, @v instead of @values), false for full size. 'false' is the default.
    • getTypeNameAlias

      String getTypeNameAlias(String typeName)
      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.
    • isAlwaysShowingType

      boolean isAlwaysShowingType()
      Returns:
      boolean true if set to always show type (@type)
    • isNeverShowingType

      boolean isNeverShowingType()
      Returns:
      boolean true if set to never show type (no @type)
    • isMinimalShowingType

      boolean isMinimalShowingType()
      Returns:
      boolean true if set to show minimal type (@type)
    • isCustomWrittenClass

      boolean isCustomWrittenClass(Class<?> clazz)
      Parameters:
      clazz - Class to check to see if there is a custom writer associated to it.
      Returns:
      boolean true if there is an associated custom writer class associated to the passed in class, false otherwise.
    • isNotCustomWrittenClass

      boolean isNotCustomWrittenClass(Class<?> clazz)
      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 writer associated to it.
      Returns:
      boolean true if the passed in class is on the not-customized list, false otherwise.
    • getAccessorsForClass

      List<Accessor> getAccessorsForClass(Class<?> c)
    • isLongDateFormat

      boolean isLongDateFormat()
      Returns:
      boolean true if java.util.Date and java.sql.Date's are being written in long (numeric) format.
    • isNonReferenceableClass

      boolean isNonReferenceableClass(Class<?> clazz)
      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.
    • getCustomWriter

      JsonWriter.JsonClassWriter getCustomWriter(Class<?> c)
      Fetch the custom writer 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 writer and store that result.
      Parameters:
      c - Class of object for which fetch a custom writer
      Returns:
      JsonClassWriter for the custom class (if one exists), null otherwise.
    • clearCaches

      void clearCaches()
    • getDeepDeclaredFields

      Map<String,Field> getDeepDeclaredFields(Class<?> c)
      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.