Package org.eclipse.ditto.json
Interface JsonField
public interface JsonField
Represents a single JSON field. A JSON field in its simplest form is a key-value-pair. Additionally a field can be
aware of its definition which allows to obtain meta information like the Java type of the value or the markers of the
field. A JSON object, for example, can be understood as a tree of JSON fields.
Implementations of this interface are required to be immutable!
-
Method Summary
Modifier and TypeMethodDescriptionReturns this JSON field's definition (meta-information).getKey()
Returns this JSON field's key.Returns the name of this JSON field's key.getValue()
Returns this JSON field's value.boolean
isMarkedAs
(JsonFieldMarker fieldMarker, JsonFieldMarker... furtherFieldMarkers) Indicates whether this field is marked with at least all specified markers.Returns aPredicate
for testing if the value of a JSON field is null.static JsonField
newInstance
(CharSequence key, JsonValue value) Returns a new JSON field based on the specified key value pair.static JsonField
newInstance
(CharSequence key, JsonValue value, JsonFieldDefinition<?> definition) Returns a new JSON field based on the specified key value pair and definition.void
writeKeyAndValue
(SerializationContext serializationContext) Writes this JsonField's key and value into the provided serialization context.
-
Method Details
-
newInstance
Returns a new JSON field based on the specified key value pair.- Parameters:
key
- the key of the field to be created.value
- the value of the field to be created.null
will be converted to the JSON NULL Literal.- Returns:
- a new JSON field containing the specified key value pair.
- Throws:
NullPointerException
- ifkey
is null.
-
newInstance
static JsonField newInstance(CharSequence key, @Nullable JsonValue value, @Nullable JsonFieldDefinition<?> definition) Returns a new JSON field based on the specified key value pair and definition.- Parameters:
key
- the key of the field to be created.value
- the value of the field to be created.null
will be converted to the JSON NULL Literal.definition
- the definition of the field to be created.- Returns:
- a new JSON field containing the specified key value pair and definition.
- Throws:
NullPointerException
- ifkey
isnull
.
-
isValueNonNull
Returns aPredicate
for testing if the value of a JSON field is null.- Returns:
- the predicate.
- See Also:
-
getKeyName
String getKeyName()Returns the name of this JSON field's key.- Returns:
- the name of this field's key.
-
getKey
JsonKey getKey()Returns this JSON field's key.- Returns:
- the key of this field.
-
getValue
JsonValue getValue()Returns this JSON field's value.- Returns:
- the value of this field.
-
getDefinition
Optional<JsonFieldDefinition> getDefinition()Returns this JSON field's definition (meta-information).- Returns:
- the definition of this field.
-
isMarkedAs
Indicates whether this field is marked with at least all specified markers. This method can only returntrue
if it has a definition.- Parameters:
fieldMarker
- the mandatory fieldMarker to check this field for.furtherFieldMarkers
- additional markers to check this field for.- Returns:
true
if this field is marked with at least all specified markers,false
else.- Throws:
NullPointerException
- if any argument isnull
.
-
writeKeyAndValue
Writes this JsonField's key and value into the provided serialization context. This is intended to be used by serialization logic only.- Parameters:
serializationContext
- the context for serialization bundling configuration and state needed for serialization.- Throws:
IOException
- in case writing the value to the backing OutputStream causes an IOException.- Since:
- 1.1.0
-