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
(@NonNull String jsonString)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()
# @NonNull String
jsonString
()Added in version 6.1.0
Returns the string representation of the JSON value.
-
asBoolean()
# boolean
asBoolean
()Added in version 6.1.0
Returns the value as a boolean. An exception is thrown if the conversion is not possible.
-
requireByKeyAsBoolean(key)
# boolean
requireByKeyAsBoolean
(@NonNull String key)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)
# boolean
getByKeyAsBoolean
(@NonNull String key,boolean
defaultValue)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()
# int
asInt
()Added in version 6.1.0
Returns the value as an integer. An exception is thrown if the conversion is not possible.
-
requireByKeyAsInt(key)
# int
requireByKeyAsInt
(@NonNull String key)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)
# int
getByKeyAsInt
(@NonNull String key,int
defaultValue)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()
# float
asFloat
()Added in version 6.1.0
Returns the value as a float. An exception is thrown if the conversion is not possible.
-
requireByKeyAsFloat(key)
# float
requireByKeyAsFloat
(@NonNull String key)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)
# float
getByKeyAsFloat
(@NonNull String key,float
defaultValue)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()
# @NonNull String
asString
()Added in version 6.1.0
Returns the value as a string. An exception is thrown if the conversion is not possible.
-
requireByKeyAsString(key)
# @NonNull String
requireByKeyAsString
(@NonNull String key)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)
# @NonNull String
getByKeyAsString
(@NonNull String key, @NonNull String defaultValue)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()
# int
asColor
()Added in version 6.1.0
Returns the value as a color. An exception is thrown if the conversion is not possible.
-
requireByKeyAsColor(key)
# int
requireByKeyAsColor
(@NonNull String key)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)
# int
getByKeyAsColor
(@NonNull String key,int
defaultValue)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.
-
asBrush()
# @NonNull Brush
asBrush
()Added in version 6.1.0
Returns the value as a Brush. An exception is thrown if the conversion is not possible.
-
requireByKeyAsBrush(key)
# Brush
requireByKeyAsBrush
(@NonNull String key)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)
# Brush
getByKeyAsBrush
(@NonNull String key, Brush defaultValue)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()
# @NonNull FloatWithUnit
asFloatWithUnit
()Added in version 6.1.0
Returns the value as a FloatWithUnit. An exception is thrown if the conversion is not possible.
-
requireByKeyAsFloatWithUnit(key)
# FloatWithUnit
requireByKeyAsFloatWithUnit
(@NonNull String key)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)
# FloatWithUnit
getByKeyAsFloatWithUnit
(@NonNull String key, FloatWithUnit defaultValue)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()
# @NonNull PointWithUnit
asPointWithUnit
()Added in version 6.1.0
Returns the value as a PointWithUnit. An exception is thrown if the conversion is not possible.
-
requireByKeyAsPointWithUnit(key)
# PointWithUnit
requireByKeyAsPointWithUnit
(@NonNull String key)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)
PointWithUnit
getByKeyAsPointWithUnit
(@NonNull String key, PointWithUnit defaultValue)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()
# @NonNull MarginsWithUnit
asMarginsWithUnit
()Added in version 6.1.0
Returns the value as a MarginsWithUnit. An exception is thrown if the conversion is not possible.
-
requireByKeyAsMarginsWithUnit(key)
# MarginsWithUnit
requireByKeyAsMarginsWithUnit
(@NonNull String key)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)
MarginsWithUnit
getByKeyAsMarginsWithUnit
(@NonNull String key, MarginsWithUnit defaultValue)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()
# @NonNull JsonValue
asArray
()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)
# @NonNull JsonValue
requireByKeyAsArray
(@NonNull String key)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)
# @Nullable JsonValue
getByKeyAsArray
(@NonNull String key, @Nullable JsonValue defaultValue)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
# long
getSize
()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)
# @NonNull JsonValue
requireByIndex
(int
index)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()
# @NonNull JsonValue
asObject
()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)
# @NonNull JsonValue
requireByKeyAsObject
(@NonNull String key)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)
# @Nullable JsonValue
getByKeyAsObject
(@NonNull String key, @Nullable JsonValue defaultValue)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)
# boolean
contains
(@NonNull String key)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.
-
requireByKey(key)
# @NonNull JsonValue
requireByKey
(@NonNull String key)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
# @NonNull String
getAbsolutePath
()Added in version 6.1.0
The path from the root to this JSON value.
-
used
# boolean
getUsed
()Added in version 6.1.0
Whether this JSON value was used during deserialization.
-