Json Value

Defined in package com.scandit.datacapture.core.json

Warning

The deserialization API is not yet stable and will still change over the coming releases.

JsonValue
class JsonValue

Added in version 6.0.0

JSON representation for use with the Scandit Data Capture SDK. It provides a lot of convenience functions for deserialization of base classes. It also tracks the usage of properties to be able to later report those that were not used for deserialization (potentially because they were misspelled or are outdated).

JsonValue()
JsonValue(jsonData: String)

Added in version 6.1.0

Returns a new JSON Value for the given json string. An exception is thrown if the string is not a valid JSON representation.

jsonString()
fun jsonString(): String

Added in version 6.1.0

Returns the string representation of the JSON value.

asBoolean()
fun asBoolean(): Boolean

Added in version 6.1.0

Returns the value as a boolean. An exception is thrown if the conversion is not possible.

requireByKeyAsBoolean(key)
fun requireByKeyAsBoolean(key: String): Boolean

Added in version 6.1.0

Returns the value for the given key as a boolean. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not a boolean.

getByKeyAsBoolean(key, defaultValue)
fun getByKeyAsBoolean(key: String,
        defaultValue: Boolean): Boolean

Added in version 6.1.0

Returns the value for the given key as a boolean. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not a boolean.

asInt()
fun asInt(): Int

Added in version 6.1.0

Returns the value as an integer. An exception is thrown if the conversion is not possible.

requireByKeyAsInt(key)
fun requireByKeyAsInt(key: String): Int

Added in version 6.1.0

Returns the value for the given key as an integer. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not an integer.

getByKeyAsInt(key, defaultValue)
fun getByKeyAsInt(key: String,
        defaultValue: Int): Int

Added in version 6.1.0

Returns the value for the given key as an integer. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not an integer.

asFloat()
fun asFloat(): Float

Added in version 6.1.0

Returns the value as a float. An exception is thrown if the conversion is not possible.

requireByKeyAsFloat(key)
fun requireByKeyAsFloat(key: String): Float

Added in version 6.1.0

Returns the value for the given key as a float. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not a float.

getByKeyAsFloat(key, defaultValue)
fun getByKeyAsFloat(key: String,
        defaultValue: Float): Float

Added in version 6.1.0

Returns the value for the given key as a float. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not a float.

asString()
fun asString(): String

Added in version 6.1.0

Returns the value as a string. An exception is thrown if the conversion is not possible.

requireByKeyAsString(key)
fun requireByKeyAsString(key: String): String

Added in version 6.1.0

Returns the value for the given key as a string. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not a string.

getByKeyAsString(key, defaultValue)
fun getByKeyAsString(key: String,
        defaultValue: String): String

Added in version 6.1.0

Returns the value for the given key as a string. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not a string.

asColor()
fun asColor(): Int

Added in version 6.1.0

Returns the value as a color. An exception is thrown if the conversion is not possible.

requireByKeyAsColor(key)
fun requireByKeyAsColor(key: String): Int

Added in version 6.1.0

Returns the value for the given key as a color. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not a color.

getByKeyAsColor(key, defaultValue)
fun getByKeyAsColor(key: String,
        defaultValue: Int): Int

Added in version 6.1.0

Returns the value for the given key as a color. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not a color.

getByKeyAsNullableColor(key, defaultValue)
fun getByKeyAsNullableColor(key: String,
        defaultValue: Int?): Int?

Added in version 7.1.0

Returns the value for the given key as a color. The default value is returned if there is no value for the given key. If this JSON Value is not an object or the value for the given key is not a color, null is returned.

asBrush()
fun asBrush(): Brush

Added in version 6.1.0

Returns the value as a Brush. An exception is thrown if the conversion is not possible.

requireByKeyAsBrush(key)
fun requireByKeyAsBrush(key: String): Brush

Added in version 6.1.0

Returns the value for the given key as a Brush. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not a Brush.

getByKeyAsBrush(key, defaultValue)
fun getByKeyAsBrush(key: String,
        defaultValue: Brush): Brush

Added in version 6.1.0

Returns the value for the given key as a Brush. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not a Brush.

asFloatWithUnit()
fun asFloatWithUnit(): FloatWithUnit

Added in version 6.1.0

Returns the value as a FloatWithUnit. An exception is thrown if the conversion is not possible.

requireByKeyAsFloatWithUnit(key)
fun requireByKeyAsFloatWithUnit(key: String): FloatWithUnit

Added in version 6.1.0

Returns the value for the given key as a FloatWithUnit. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not a FloatWithUnit.

getByKeyAsFloatWithUnit(key, defaultValue)
fun getByKeyAsFloatWithUnit(key: String,
        defaultValue: FloatWithUnit): FloatWithUnit

Added in version 6.1.0

Returns the value for the given key as a FloatWithUnit. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not a FloatWithUnit.

asPointWithUnit()
fun asPointWithUnit(): PointWithUnit

Added in version 6.1.0

Returns the value as a PointWithUnit. An exception is thrown if the conversion is not possible.

requireByKeyAsPointWithUnit(key)
fun requireByKeyAsPointWithUnit(key: String): PointWithUnit

Added in version 6.1.0

Returns the value for the given key as a PointWithUnit. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not a PointWithUnit.

getByKeyAsPointWithUnit(key, defaultValue)
fun getByKeyAsPointWithUnit(key: String,
        defaultValue: PointWithUnit): PointWithUnit

Added in version 6.1.0

Returns the value for the given key as a PointWithUnit. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not a PointWithUnit.

asMarginsWithUnit()
fun asMarginsWithUnit(): MarginsWithUnit

Added in version 6.1.0

Returns the value as a MarginsWithUnit. An exception is thrown if the conversion is not possible.

requireByKeyAsMarginsWithUnit(key)
fun requireByKeyAsMarginsWithUnit(key: String): MarginsWithUnit

Added in version 6.1.0

Returns the value for the given key as a MarginsWithUnit. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not a MarginsWithUnit.

getByKeyAsMarginsWithUnit(key, defaultValue)
fun getByKeyAsMarginsWithUnit(key: String,
        defaultValue: MarginsWithUnit): MarginsWithUnit

Added in version 6.1.0

Returns the value for the given key as a MarginsWithUnit. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not a MarginsWithUnit.

asArray()
fun asArray(): JsonValue

Added in version 6.1.0

Returns the value if it is an array. An exception is thrown if the conversion is not possible.

requireByKeyAsArray(key)
fun requireByKeyAsArray(key: String): JsonValue

Added in version 6.1.0

Returns the value for the given key as an array. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not an array.

getByKeyAsArray(key, defaultValue)
fun getByKeyAsArray(key: String,
        defaultValue: JsonValue?): JsonValue?

Added in version 6.1.0

Returns the value for the given key as an array. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not an array.

size
val size: Long

Added in version 6.1.0

The size of the array. An exception is thrown if this JSON value is not an array.

requireByIndex(index)
fun requireByIndex(index: Int): JsonValue

Added in version 6.1.0

Returns the value for the given index. An exception is thrown if this JSON Value is not an array or the given index is out of bounds.

asObject()
fun asObject(): JsonValue

Added in version 6.1.0

Returns the value if it is an object. An exception is thrown if the conversion is not possible.

requireByKeyAsObject(key)
fun requireByKeyAsObject(key: String): JsonValue

Added in version 6.1.0

Returns the value for the given key as an object. An exception is thrown if this JSON Value is not an object, it does not contain a value for the given key or the value for the given key is not an object.

getByKeyAsObject(key, defaultValue)
fun getByKeyAsObject(key: String,
        defaultValue: JsonValue?): JsonValue?

Added in version 6.1.0

Returns the value for the given key as an object. The default value is returned if there is no value for the given key. An exception is thrown if this JSON Value is not an object or the value for the given key is not an object.

contains(key)
fun contains(key: String): Boolean

Added in version 6.1.0

Returns whether a value for the given key exists. An exception is thrown if this JSON Value is not an object.

containsNull(key)
fun containsNull(key: String): Boolean

Added in version 7.1.0

Returns whether a null value for the given key exists. An exception is thrown if this JSON Value is not an object.

requireByKey(key)
fun requireByKey(key: String): JsonValue

Added in version 6.1.0

Returns the value for the given key. An exception is thrown if this JSON Value is not an object or it does not contain a value for the given key.

absolutePath
val absolutePath: String

Added in version 6.1.0

The path from the root to this JSON value.

used
val used: Boolean

Added in version 6.1.0

Whether this JSON value was used during deserialization.