JsonBuilder

Builder of the Json instance provided by Json { ... } factory function.

class JsonBuilder

Functions

equals
Link copied to clipboard
common
open operator override fun equals(other: Any?): Boolean
hashCode
Link copied to clipboard
common
open override fun hashCode(): Int
toString
Link copied to clipboard
common
open override fun toString(): String

Properties

allowSpecialFloatingPointValues
Link copied to clipboard
common

Removes JSON specification restriction on special floating-point values such as NaN and Infinity and enables their serialization and deserialization. When enabling it, please ensure that the receiving party will be able to encode and decode these special values. false by default.

var allowSpecialFloatingPointValues: Boolean
allowStructuredMapKeys
Link copied to clipboard
common

Enables structured objects to be serialized as map keys by changing serialized form of the map from JSON object (key-value pairs) to flat array like [k1, v1, k2, v2]. false by default.

var allowStructuredMapKeys: Boolean
classDiscriminator
Link copied to clipboard
common

Name of the class descriptor property for polymorphic serialization. "type" by default.

var classDiscriminator: String
coerceInputValues
Link copied to clipboard
common

Enables coercing incorrect JSON values to the default property value in the following cases:

  1. JSON value is null but property type is non-nullable.

  2. Property type is an enum type, but JSON value contains unknown enum member.

false by default.

var coerceInputValues: Boolean
encodeDefaults
Link copied to clipboard
common

Specifies whether default values of Kotlin properties should be encoded. false by default.

var encodeDefaults: Boolean
explicitNulls
Link copied to clipboard
common

Specifies whether null values should be encoded for nullable properties and must be present in JSON object during decoding.

When this flag is disabled properties with null values without default are not encoded; during decoding, the absence of a field value is treated as null for nullable properties without a default value.

true by default.

var explicitNulls: Boolean
ignoreUnknownKeys
Link copied to clipboard
common

Specifies whether encounters of unknown properties in the input JSON should be ignored instead of throwing SerializationException. false by default.

var ignoreUnknownKeys: Boolean
isLenient
Link copied to clipboard
common

Removes JSON specification restriction (RFC-4627) and makes parser more liberal to the malformed input. In lenient mode quoted boolean literals, and unquoted string literals are allowed.

Its relaxations can be expanded in the future, so that lenient parser becomes even more permissive to invalid value in the input, replacing them with defaults.

false by default.

var isLenient: Boolean
prettyPrint
Link copied to clipboard
common

Specifies whether resulting JSON should be pretty-printed. false by default.

var prettyPrint: Boolean
prettyPrintIndent
Link copied to clipboard
common

Specifies indent string to use with prettyPrint mode 4 spaces by default. Experimentality note: this API is experimental because it is not clear whether this option has compelling use-cases.

var prettyPrintIndent: String
serializersModule
Link copied to clipboard
common

Module with contextual and polymorphic serializers to be used in the resulting Json instance.

var serializersModule: SerializersModule
useAlternativeNames
Link copied to clipboard
common

Specifies whether Json instance makes use of JsonNames annotation.

Disabling this flag when one does not use JsonNames at all may sometimes result in better performance, particularly when a large count of fields is skipped with ignoreUnknownKeys. true by default.

var useAlternativeNames: Boolean
useArrayPolymorphism
Link copied to clipboard
common

Switches polymorphic serialization to the default array format. This is an option for legacy JSON format and should not be generally used. false by default.

var useArrayPolymorphism: Boolean