Class JsonField
-
- All Implemented Interfaces:
public class JsonField<T extends Object>
A class representing a serializable JSON field.
It can either be a KnownValue value of type T, matching the type the SDK expects, or an arbitrary JSON value that bypasses the type system (via JsonValue).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interface
JsonField.Visitor
An interface that defines how to map each possible state of a
JsonField<T>
to a value of type R.public final class
JsonField.IsMissing
This class is a Jackson filter that can be used to exclude missing properties from objects. This filter should not be used directly and should instead use the @ExcludeMissing annotation.
public final class
JsonField.Deserializer
-
Method Summary
Modifier and Type Method Description final Boolean
isMissing()
Returns whether this field is missing, which means it will be omitted from the serialized JSON entirely. final Boolean
isNull()
Whether this field is explicitly set to null
.final Optional<T>
asKnown()
Returns an Optional containing this field's "known" value, meaning it matches the type the SDK expects, or an empty Optional if this field contains an arbitrary JsonValue. final Optional<JsonValue>
asUnknown()
Returns an Optional containing this field's arbitrary JsonValue, meaning it mismatches the type the SDK expects, or an empty Optional if this field contains a "known" value. final Optional<Boolean>
asBoolean()
Returns an Optional containing this field's boolean value, or an empty Optional if it doesn't contain a boolean. final Optional<Number>
asNumber()
Returns an Optional containing this field's numerical value, or an empty Optional if it doesn't contain a number. final Optional<String>
asString()
Returns an Optional containing this field's string value, or an empty Optional if it doesn't contain a string. final String
asStringOrThrow()
final Optional<List<JsonValue>>
asArray()
Returns an Optional containing this field's list value, or an empty Optional if it doesn't contain a list. final Optional<Map<String, JsonValue>>
asObject()
Returns an Optional containing this field's map value, or an empty Optional if it doesn't contain a map. final <R extends Any> R
accept(JsonField.Visitor<T, R> visitor)
Returns the result of calling the visitor method corresponding to this field's state. final static <T extends Any> JsonField<T>
of(T value)
Returns a JsonField containing the given "known" value. final static <T extends Any> JsonField<T>
ofNullable(T value)
Returns a JsonField containing the given "known" value, or JsonNull if value is null. -
-
Method Detail
-
isMissing
final Boolean isMissing()
Returns whether this field is missing, which means it will be omitted from the serialized JSON entirely.
-
asKnown
final Optional<T> asKnown()
Returns an Optional containing this field's "known" value, meaning it matches the type the SDK expects, or an empty Optional if this field contains an arbitrary JsonValue.
This is the opposite of asUnknown.
-
asUnknown
final Optional<JsonValue> asUnknown()
Returns an Optional containing this field's arbitrary JsonValue, meaning it mismatches the type the SDK expects, or an empty Optional if this field contains a "known" value.
This is the opposite of asKnown.
-
asBoolean
final Optional<Boolean> asBoolean()
Returns an Optional containing this field's boolean value, or an empty Optional if it doesn't contain a boolean.
This method checks for both a KnownValue containing a boolean and for JsonBoolean.
-
asNumber
final Optional<Number> asNumber()
Returns an Optional containing this field's numerical value, or an empty Optional if it doesn't contain a number.
This method checks for both a KnownValue containing a number and for JsonNumber.
-
asString
final Optional<String> asString()
Returns an Optional containing this field's string value, or an empty Optional if it doesn't contain a string.
This method checks for both a KnownValue containing a string and for JsonString.
-
asStringOrThrow
final String asStringOrThrow()
-
asArray
final Optional<List<JsonValue>> asArray()
Returns an Optional containing this field's list value, or an empty Optional if it doesn't contain a list.
This method checks for both a KnownValue containing a list and for JsonArray.
-
asObject
final Optional<Map<String, JsonValue>> asObject()
Returns an Optional containing this field's map value, or an empty Optional if it doesn't contain a map.
This method checks for both a KnownValue containing a map and for JsonObject.
-
accept
final <R extends Any> R accept(JsonField.Visitor<T, R> visitor)
Returns the result of calling the visitor method corresponding to this field's state.
-
ofNullable
final static <T extends Any> JsonField<T> ofNullable(T value)
-
-
-
-