public interface JSONDataType extends DataType<JSON>
For efficiency, the JSON value is serialized in binary form following the CBOR specification.
The implementation provides support for binary
deltas
.
DataTypes.json()
Modifier and Type | Method and Description |
---|---|
DeltaType<JSON,BinaryDelta> |
binaryDeltaType()
Returns support for binary deltas.
|
JSON |
fromJsonString(String json)
Parse a JSON string.
|
<T> T |
readAs(Class<T> classOfT,
byte[] bytes)
Create a value of a compatible class from binary.
|
<T> T |
readAs(Class<T> classOfT,
byte[] bytes,
int offset,
int length)
Create a value of a compatible class from a binary.
|
<T> T |
readAs(Class<T> classOfT,
Bytes bytes)
Create a value of a compatible class from binary.
|
JSON |
readValue(byte[] bytes)
Parse a value from CBOR-format binary.
|
JSON |
readValue(byte[] bytes,
int offset,
int length)
Parse a value from CBOR-format binary.
|
JSON |
readValue(Bytes bytes)
Parse a value from CBOR-format binary.
|
canReadAs, deltaType, deltaType, getTypeName, toBytes, validate, writeValue
DeltaType<JSON,BinaryDelta> binaryDeltaType()
Equivalent to calling deltaType(BinaryDelta.class)
.
binaryDeltaType
in interface DataType<JSON>
JSON fromJsonString(String json) throws InvalidDataException
Precision for numeric types is lost in the translation to the internal
CBOR binary form and non-significant white space is not preserved. It is
not guaranteed that fromJsonString(json).toJsonString()
equals
json
.
InvalidDataException
- if json does not represent a single JSON
valueJSON readValue(byte[] bytes, int offset, int length) throws IndexOutOfBoundsException
JSON instances defer parsing of binary data until required so this method
does not throw InvalidDataException
. If the data is not valid, an
InvalidDataException
may be thrown when a JSON
method is
called.
readValue
in interface DataType<JSON>
bytes
- the binary data. The implementation re-uses the array to avoid
copying. The caller must ensure the array is not modified.offset
- start of the data within byteslength
- length of the data within bytesIndexOutOfBoundsException
- if either offset
or
length
is negative, or
offset + length > bytes.length
DataType.validate(V)
JSON readValue(byte[] bytes)
readValue(in, 0, in.length)
.JSON readValue(Bytes bytes)
readValue(bytes.toByteArray())
.<T> T readAs(Class<T> classOfT, byte[] bytes, int offset, int length) throws IllegalArgumentException, IndexOutOfBoundsException
If valueType
is incompatible with this data type, this method
will throw an IllegalArgumentException. Compatibility can be tested with
DataType.canReadAs(Class)
.
JSON instances defer parsing of binary data until required so this method
does not throw InvalidDataException
. If the data is not valid, an
InvalidDataException
may be thrown when a JSON
method is
called.
readAs
in interface DataType<JSON>
T
- type of classOfT
classOfT
- the type of the resultbytes
- The binary data. The implementation may re-use the array to
avoid copying so the caller must ensure the array is not modified.offset
- start of the data within byteslength
- length of the data within bytesIllegalArgumentException
- if classOfT
is
incompatible with this data typeIndexOutOfBoundsException
- if either offset
or
length
is negative, or
offset + length > bytes.length
<T> T readAs(Class<T> classOfT, byte[] bytes) throws IllegalArgumentException
readAs(classOfT, in, 0,
in.length)
.
JSON instances defer parsing of binary data until required so this method
does not throw InvalidDataException
. If the data is not valid, an
InvalidDataException
may be thrown when a JSON
method is
called.
readAs
in interface DataType<JSON>
T
- type of classOfT
classOfT
- the type of the resultbytes
- The binary data. The implementation may re-use the array to
avoid copying so the caller must ensure the array is not modified.IllegalArgumentException
- if classOfT
is
incompatible with this data type<T> T readAs(Class<T> classOfT, Bytes bytes) throws IllegalArgumentException
readAs(classOfT, bytes.toByteArray())
.
JSON instances defer parsing of binary data until required so this method
does not throw InvalidDataException
. If the data is not valid, an
InvalidDataException
may be thrown when a JSON
method is
called.
readAs
in interface DataType<JSON>
T
- type of classOfT
classOfT
- the type of the resultbytes
- the binary dataIllegalArgumentException
- if classOfT
is
incompatible with this data typeCopyright © 2020 Push Technology Ltd. All Rights Reserved.