public interface Value
You can check type first using isXxx() methods or getValueType()
method, then convert the value to a
subtype using asXxx() methods. You can also call asXxx() methods directly and catch
MessageTypeCastException
.
MessagePack type | Check method | Convert method | Value type |
---|---|---|---|
Nil | isNilValue() | asNumberValue() | NilValue |
Boolean | isBooleanValue() | asBooleanValue() | BooleanValue |
Integer or Float | isNumberValue() | asNumberValue() | NumberValue |
Integer | isIntegerValue() | asIntegerValue() | IntegerValue |
Float | isFloatValue() | asFloatValue() | FloatValue |
String or Binary | isRawValue() | asRawValue() | RawValue |
String | isStringValue() | asStringValue() | StringValue |
Binary | isBinaryValue() | asBinaryValue() | BinaryValue |
Array | isArrayValue() | asArrayValue() | ArrayValue |
Map | isMapValue() | asMapValue() | MapValue |
Extension | isExtensionValue() | asExtensionValue() | ExtensionValue |
Value interface is the base interface of all Value interfaces. Immutable subtypes are useful so that you can declare that a (final) field or elements of a container object are immutable. Method arguments should be a regular Value interface generally.
You can use immutableValue()
method to get immutable subtypes.
MessagePack type | Subtype method | Immutable value type |
---|---|---|
any types | Value .immutableValue() | ImmutableValue |
Nil | NilValue .immutableValue() | ImmutableNilValue |
Boolean | BooleanValue .immutableValue() | ImmutableBooleanValue |
Integer | IntegerValue .immutableValue() | ImmutableIntegerValue |
Float | FloatValue .immutableValue() | ImmutableFloatValue |
Integer or Float | NumberValue .immutableValue() | ImmutableNumberValue |
String or Binary | RawValue .immutableValue() | ImmutableRawValue |
String | StringValue .immutableValue() | ImmutableStringValue |
Binary | BinaryValue .immutableValue() | ImmutableBinaryValue |
Array | ArrayValue .immutableValue() | ImmutableArrayValue |
Map | MapValue .immutableValue() | ImmutableMapValue |
Extension | ExtensionValue .immutableValue() | ImmutableExtensionValue |
toJson()
method returns JSON representation of a Value. See its documents for details.
toString() also returns a string representation of a Value that is similar to JSON. However, unlike toJson() method, toString() may return a special format that is not be compatible with JSON when JSON doesn't support the type such as ExtensionValue.
Modifier and Type | Method and Description |
---|---|
ArrayValue |
asArrayValue()
Returns the value as
ArrayValue . |
BinaryValue |
asBinaryValue()
Returns the value as
BinaryValue . |
BooleanValue |
asBooleanValue()
Returns the value as
BooleanValue . |
ExtensionValue |
asExtensionValue()
Returns the value as
ExtensionValue . |
FloatValue |
asFloatValue()
Returns the value as
FloatValue . |
IntegerValue |
asIntegerValue()
Returns the value as
IntegerValue . |
MapValue |
asMapValue()
Returns the value as
MapValue . |
NilValue |
asNilValue()
Returns the value as
NilValue . |
NumberValue |
asNumberValue()
Returns the value as
NumberValue . |
RawValue |
asRawValue()
Returns the value as
RawValue . |
StringValue |
asStringValue()
Returns the value as
StringValue . |
boolean |
equals(java.lang.Object obj)
Compares this value to the specified object.
|
ValueType |
getValueType()
Returns type of this value.
|
ImmutableValue |
immutableValue()
Returns immutable copy of this value.
|
boolean |
isArrayValue()
Returns true if type of this value is Array.
|
boolean |
isBinaryValue()
Returns true if type of this value is Binary.
|
boolean |
isBooleanValue()
Returns true if type of this value is Boolean.
|
boolean |
isExtensionValue()
Returns true if type of this an Extension.
|
boolean |
isFloatValue()
Returns true if type of this value is Float.
|
boolean |
isIntegerValue()
Returns true if type of this value is Integer.
|
boolean |
isMapValue()
Returns true if type of this value is Map.
|
boolean |
isNilValue()
Returns true if type of this value is Nil.
|
boolean |
isNumberValue()
Returns true if type of this value is Integer or Float.
|
boolean |
isRawValue()
Returns true if type of this value is String or Binary.
|
boolean |
isStringValue()
Returns true if type of this value is String.
|
java.lang.String |
toJson()
Returns json representation of this Value.
|
void |
writeTo(MessagePacker pk)
Serializes the value using the specified
MessagePacker |
ValueType getValueType()
instanceof
to check type of a value because type of a mutable value is variable.ImmutableValue immutableValue()
this
without copying the value if this value is already immutable.boolean isNilValue()
asNilValue
never throws exceptions.
Note that you can't use instanceof
or cast ((NilValue) thisValue)
to check type of a value because type of a mutable value is variable.boolean isBooleanValue()
asBooleanValue
never throws exceptions.
Note that you can't use instanceof
or cast ((BooleanValue) thisValue)
to check type of a value because type of a mutable value is variable.boolean isNumberValue()
asNumberValue
never throws exceptions.
Note that you can't use instanceof
or cast ((NumberValue) thisValue)
to check type of a value because type of a mutable value is variable.boolean isIntegerValue()
asIntegerValue
never throws exceptions.
Note that you can't use instanceof
or cast ((IntegerValue) thisValue)
to check type of a value because type of a mutable value is variable.boolean isFloatValue()
asFloatValue
never throws exceptions.
Note that you can't use instanceof
or cast ((FloatValue) thisValue)
to check type of a value because type of a mutable value is variable.boolean isRawValue()
asRawValue
never throws exceptions.
Note that you can't use instanceof
or cast ((RawValue) thisValue)
to check type of a value because type of a mutable value is variable.boolean isBinaryValue()
asBinaryValue
never throws exceptions.
Note that you can't use instanceof
or cast ((BinaryValue) thisValue)
to check type of a value because type of a mutable value is variable.boolean isStringValue()
asStringValue
never throws exceptions.
Note that you can't use instanceof
or cast ((StringValue) thisValue)
to check type of a value because type of a mutable value is variable.boolean isArrayValue()
asArrayValue
never throws exceptions.
Note that you can't use instanceof
or cast ((ArrayValue) thisValue)
to check type of a value because type of a mutable value is variable.boolean isMapValue()
asMapValue
never throws exceptions.
Note that you can't use instanceof
or cast ((MapValue) thisValue)
to check type of a value because type of a mutable value is variable.boolean isExtensionValue()
asExtensionValue
never throws exceptions.
Note that you can't use instanceof
or cast ((ExtensionValue) thisValue)
to check type of a value because
type of a mutable value is variable.NilValue asNilValue()
NilValue
. Otherwise throws MessageTypeCastException
.
Note that you can't use instanceof
or cast ((NilValue) thisValue)
to check type of a value because type of a mutable value is variable.MessageTypeCastException
- If type of this value is not Nil.BooleanValue asBooleanValue()
BooleanValue
. Otherwise throws MessageTypeCastException
.
Note that you can't use instanceof
or cast ((BooleanValue) thisValue)
to check type of a value because type of a mutable value is variable.MessageTypeCastException
- If type of this value is not Boolean.NumberValue asNumberValue()
NumberValue
. Otherwise throws MessageTypeCastException
.
Note that you can't use instanceof
or cast ((NumberValue) thisValue)
to check type of a value because type of a mutable value is variable.MessageTypeCastException
- If type of this value is not Integer or Float.IntegerValue asIntegerValue()
IntegerValue
. Otherwise throws MessageTypeCastException
.
Note that you can't use instanceof
or cast ((IntegerValue) thisValue)
to check type of a value because type of a mutable value is variable.MessageTypeCastException
- If type of this value is not Integer.FloatValue asFloatValue()
FloatValue
. Otherwise throws MessageTypeCastException
.
Note that you can't use instanceof
or cast ((FloatValue) thisValue)
to check type of a value because type of a mutable value is variable.MessageTypeCastException
- If type of this value is not Float.RawValue asRawValue()
RawValue
. Otherwise throws MessageTypeCastException
.
Note that you can't use instanceof
or cast ((RawValue) thisValue)
to check type of a value because type of a mutable value is variable.MessageTypeCastException
- If type of this value is not Binary or String.BinaryValue asBinaryValue()
BinaryValue
. Otherwise throws MessageTypeCastException
.
Note that you can't use instanceof
or cast ((BinaryValue) thisValue)
to check type of a value because type of a mutable value is variable.MessageTypeCastException
- If type of this value is not Binary.StringValue asStringValue()
StringValue
. Otherwise throws MessageTypeCastException
.
Note that you can't use instanceof
or cast ((StringValue) thisValue)
to check type of a value because type of a mutable value is variable.MessageTypeCastException
- If type of this value is not String.ArrayValue asArrayValue()
ArrayValue
. Otherwise throws MessageTypeCastException
.
Note that you can't use instanceof
or cast ((ArrayValue) thisValue)
to check type of a value because type of a mutable value is variable.MessageTypeCastException
- If type of this value is not Array.MapValue asMapValue()
MapValue
. Otherwise throws MessageTypeCastException
.
Note that you can't use instanceof
or cast ((MapValue) thisValue)
to check type of a value because type of a mutable value is variable.MessageTypeCastException
- If type of this value is not Map.ExtensionValue asExtensionValue()
ExtensionValue
. Otherwise throws MessageTypeCastException
.
Note that you can't use instanceof
or cast ((ExtensionValue) thisValue)
to check type of a value
because type of a mutable value is variable.MessageTypeCastException
- If type of this value is not an Extension.void writeTo(MessagePacker pk) throws java.io.IOException
MessagePacker
java.io.IOException
MessagePacker
boolean equals(java.lang.Object obj)
true
if type and value are equivalent.
If this value is MapValue
or ArrayValue
, this method check equivalence of elements recursively.equals
in class java.lang.Object
java.lang.String toJson()
Following behavior is not configurable at this release and they might be changed at future releases:
U+FFFD replacement character
.U+FFFD replacement character