Class DefaultJsonSerializationContext.Builder

java.lang.Object
org.dominokit.jacksonapt.DefaultJsonSerializationContext.Builder
Direct Known Subclasses:
DefaultJsonSerializationContext.DefaultBuilder
Enclosing class:
DefaultJsonSerializationContext

public static class DefaultJsonSerializationContext.Builder
extends java.lang.Object
Builder for JsonSerializationContext. To override default settings globally, you can extend this class, modify the default settings inside the constructor and tell the compiler to use your builder instead in your gwt.xml file :
 

 <replace-with class="your.package.YourBuilder">
   <when-type-assignable class="org.dominokit.jacksonapt.JsonSerializationContext.Builder" />
 </replace-with>

 
 
  • Field Details

    • useEqualityForObjectId

      protected boolean useEqualityForObjectId
    • serializeNulls

      protected boolean serializeNulls
    • writeDatesAsTimestamps

      protected boolean writeDatesAsTimestamps
    • writeDateKeysAsTimestamps

      protected boolean writeDateKeysAsTimestamps
    • indent

      protected boolean indent
    • wrapRootValue

      protected boolean wrapRootValue
    • writeCharArraysAsJsonArrays

      protected boolean writeCharArraysAsJsonArrays
    • writeNullMapValues

      protected boolean writeNullMapValues
    • writeEmptyJsonArrays

      protected boolean writeEmptyJsonArrays
    • orderMapEntriesByKeys

      protected boolean orderMapEntriesByKeys
    • writeSingleElemArraysUnwrapped

      protected boolean writeSingleElemArraysUnwrapped
    • wrapExceptions

      protected boolean wrapExceptions
  • Constructor Details

  • Method Details

    • useEqualityForObjectId

      public DefaultJsonSerializationContext.Builder useEqualityForObjectId​(boolean useEqualityForObjectId)
      Determines whether Object Identity is compared using true JVM-level identity of Object (false); or, equals() method. Latter is sometimes useful when dealing with Database-bound objects with ORM libraries (like Hibernate).

      Option is disabled by default; meaning that strict identity is used, not equals()

      Parameters:
      useEqualityForObjectId - true if should useEqualityForObjectId
      Returns:
      the builder
    • serializeNulls

      public DefaultJsonSerializationContext.Builder serializeNulls​(boolean serializeNulls)
      Sets whether object members are serialized when their value is null. This has no impact on array elements. The default is true.
      Parameters:
      serializeNulls - true if should serializeNulls
      Returns:
      the builder
    • writeDatesAsTimestamps

      public DefaultJsonSerializationContext.Builder writeDatesAsTimestamps​(boolean writeDatesAsTimestamps)
      Determines whether Date and Timestamp values are to be serialized as numeric timestamps (true; the default), or as textual representation.

      If textual representation is used, the actual format is Option is enabled by default.

      Parameters:
      writeDatesAsTimestamps - true if should writeDatesAsTimestamps
      Returns:
      the builder
    • writeDateKeysAsTimestamps

      public DefaultJsonSerializationContext.Builder writeDateKeysAsTimestamps​(boolean writeDateKeysAsTimestamps)
      Feature that determines whether Dates and Timestamps used as Map keys are serialized as timestamps or as textual values.

      If textual representation is used, the actual format is Option is disabled by default.

      Parameters:
      writeDateKeysAsTimestamps - true if should writeDateKeysAsTimestamps
      Returns:
      the builder
    • indent

      public DefaultJsonSerializationContext.Builder indent​(boolean indent)
      Feature that allows enabling (or disabling) indentation for the underlying writer.

      Feature is disabled by default.

      Parameters:
      indent - true if should indent
      Returns:
      the builder
    • wrapRootValue

      public DefaultJsonSerializationContext.Builder wrapRootValue​(boolean wrapRootValue)
      Feature that can be enabled to make root value (usually JSON Object but can be any type) wrapped within a single property JSON object, where key as the "root name", as determined by annotation introspector or fallback (non-qualified class name).

      Feature is disabled by default.

      Parameters:
      wrapRootValue - true if should wrapRootValue
      Returns:
      the builder
    • writeCharArraysAsJsonArrays

      public DefaultJsonSerializationContext.Builder writeCharArraysAsJsonArrays​(boolean writeCharArraysAsJsonArrays)
      Feature that determines how type char[] is serialized: when enabled, will be serialized as an explict JSON array (with single-character Strings as values); when disabled, defaults to serializing them as Strings (which is more compact).

      Feature is disabled by default.

      Parameters:
      writeCharArraysAsJsonArrays - true if should writeCharArraysAsJsonArrays
      Returns:
      the builder
    • writeNullMapValues

      public DefaultJsonSerializationContext.Builder writeNullMapValues​(boolean writeNullMapValues)
      Feature that determines whether Map entries with null values are to be serialized (true) or not (false).

      Feature is enabled by default.

      Parameters:
      writeNullMapValues - true if should writeNullMapValues
      Returns:
      the builder
    • writeEmptyJsonArrays

      public DefaultJsonSerializationContext.Builder writeEmptyJsonArrays​(boolean writeEmptyJsonArrays)
      Feature that determines whether Container properties (POJO properties with declared value of Collection or array; i.e. things that produce JSON arrays) that are empty (have no elements) will be serialized as empty JSON arrays (true), or suppressed from output (false).

      Note that this does not change behavior of Maps, or "Collection-like" types.

      Feature is enabled by default.

      Parameters:
      writeEmptyJsonArrays - true if should writeEmptyJsonArrays
      Returns:
      the builder
    • orderMapEntriesByKeys

      public DefaultJsonSerializationContext.Builder orderMapEntriesByKeys​(boolean orderMapEntriesByKeys)
      Feature that determines whether Map entries are first sorted by key before serialization or not: if enabled, additional sorting step is performed if necessary (not necessary for SortedMaps), if disabled, no additional sorting is needed.

      Feature is disabled by default.

      Parameters:
      orderMapEntriesByKeys - true if should orderMapEntriesByKeys
      Returns:
      the builder
    • writeSingleElemArraysUnwrapped

      public DefaultJsonSerializationContext.Builder writeSingleElemArraysUnwrapped​(boolean writeSingleElemArraysUnwrapped)
      Feature added for interoperability, to work with oddities of so-called "BadgerFish" convention. Feature determines handling of single element Collections and arrays: if enabled, Collections and arrays that contain exactly one element will be serialized as if that element itself was serialized.

      When enabled, a POJO with array that normally looks like this:
        { "arrayProperty" : [ 1 ] }
       
      will instead be serialized as
        { "arrayProperty" : 1 }
       

      Note that this feature is counterpart to DefaultJsonDeserializationContext.Builder.acceptSingleValueAsArray(boolean) (that is, usually both are enabled, or neither is).

      Feature is disabled by default, so that no special handling is done.
      Parameters:
      writeSingleElemArraysUnwrapped - true if should writeSingleElemArraysUnwrapped
      Returns:
      the builder
    • wrapExceptions

      public DefaultJsonSerializationContext.Builder wrapExceptions​(boolean wrapExceptions)
      Feature that determines whether gwt-jackson code should catch and wrap RuntimeExceptions (but never Errors!) to add additional information about location (within input) of problem or not. If enabled, exceptions will be caught and re-thrown; this can be convenient both in that all exceptions will be checked and declared, and so there is more contextual information. However, sometimes calling application may just want "raw" unchecked exceptions passed as is.

      Feature is enabled by default.
      Parameters:
      wrapExceptions - true if should wrapExceptions
      Returns:
      the builder
    • build

      public final JsonSerializationContext build()