Interface Value
-
- All Known Subinterfaces:
ArrayValue
,BinaryValue
,BooleanValue
,ExtensionValue
,FloatValue
,ImmutableArrayValue
,ImmutableBinaryValue
,ImmutableBooleanValue
,ImmutableExtensionValue
,ImmutableFloatValue
,ImmutableIntegerValue
,ImmutableMapValue
,ImmutableNilValue
,ImmutableNumberValue
,ImmutableRawValue
,ImmutableStringValue
,ImmutableValue
,IntegerValue
,MapValue
,NilValue
,NumberValue
,RawValue
,StringValue
- All Known Implementing Classes:
AbstractImmutableRawValue
,ImmutableArrayValueImpl
,ImmutableBigIntegerValueImpl
,ImmutableBinaryValueImpl
,ImmutableBooleanValueImpl
,ImmutableDoubleValueImpl
,ImmutableExtensionValueImpl
,ImmutableLongValueImpl
,ImmutableMapValueImpl
,ImmutableNilValueImpl
,ImmutableStringValueImpl
,Variable
public interface Value
Value stores a value and its type in MessagePack type system.Type conversion
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 catchMessageTypeCastException
.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
Immutable interface
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
Converting to JSON
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.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ArrayValue
asArrayValue()
Returns the value asArrayValue
.BinaryValue
asBinaryValue()
Returns the value asBinaryValue
.BooleanValue
asBooleanValue()
Returns the value asBooleanValue
.ExtensionValue
asExtensionValue()
Returns the value asExtensionValue
.FloatValue
asFloatValue()
Returns the value asFloatValue
.IntegerValue
asIntegerValue()
Returns the value asIntegerValue
.MapValue
asMapValue()
Returns the value asMapValue
.NilValue
asNilValue()
Returns the value asNilValue
.NumberValue
asNumberValue()
Returns the value asNumberValue
.RawValue
asRawValue()
Returns the value asRawValue
.StringValue
asStringValue()
Returns the value asStringValue
.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 specifiedMessagePacker
-
-
-
Method Detail
-
getValueType
ValueType getValueType()
Returns type of this value. Note that you can't useinstanceof
to check type of a value because type of a mutable value is variable.
-
immutableValue
ImmutableValue immutableValue()
Returns immutable copy of this value. This method simply returnsthis
without copying the value if this value is already immutable.
-
isNilValue
boolean isNilValue()
Returns true if type of this value is Nil. If this method returns true,asNilValue
never throws exceptions. Note that you can't useinstanceof
or cast((NilValue) thisValue)
to check type of a value because type of a mutable value is variable.
-
isBooleanValue
boolean isBooleanValue()
Returns true if type of this value is Boolean. If this method returns true,asBooleanValue
never throws exceptions. Note that you can't useinstanceof
or cast((BooleanValue) thisValue)
to check type of a value because type of a mutable value is variable.
-
isNumberValue
boolean isNumberValue()
Returns true if type of this value is Integer or Float. If this method returns true,asNumberValue
never throws exceptions. Note that you can't useinstanceof
or cast((NumberValue) thisValue)
to check type of a value because type of a mutable value is variable.
-
isIntegerValue
boolean isIntegerValue()
Returns true if type of this value is Integer. If this method returns true,asIntegerValue
never throws exceptions. Note that you can't useinstanceof
or cast((IntegerValue) thisValue)
to check type of a value because type of a mutable value is variable.
-
isFloatValue
boolean isFloatValue()
Returns true if type of this value is Float. If this method returns true,asFloatValue
never throws exceptions. Note that you can't useinstanceof
or cast((FloatValue) thisValue)
to check type of a value because type of a mutable value is variable.
-
isRawValue
boolean isRawValue()
Returns true if type of this value is String or Binary. If this method returns true,asRawValue
never throws exceptions. Note that you can't useinstanceof
or cast((RawValue) thisValue)
to check type of a value because type of a mutable value is variable.
-
isBinaryValue
boolean isBinaryValue()
Returns true if type of this value is Binary. If this method returns true,asBinaryValue
never throws exceptions. Note that you can't useinstanceof
or cast((BinaryValue) thisValue)
to check type of a value because type of a mutable value is variable.
-
isStringValue
boolean isStringValue()
Returns true if type of this value is String. If this method returns true,asStringValue
never throws exceptions. Note that you can't useinstanceof
or cast((StringValue) thisValue)
to check type of a value because type of a mutable value is variable.
-
isArrayValue
boolean isArrayValue()
Returns true if type of this value is Array. If this method returns true,asArrayValue
never throws exceptions. Note that you can't useinstanceof
or cast((ArrayValue) thisValue)
to check type of a value because type of a mutable value is variable.
-
isMapValue
boolean isMapValue()
Returns true if type of this value is Map. If this method returns true,asMapValue
never throws exceptions. Note that you can't useinstanceof
or cast((MapValue) thisValue)
to check type of a value because type of a mutable value is variable.
-
isExtensionValue
boolean isExtensionValue()
Returns true if type of this an Extension. If this method returns true,asExtensionValue
never throws exceptions. Note that you can't useinstanceof
or cast((ExtensionValue) thisValue)
to check type of a value because type of a mutable value is variable.
-
asNilValue
NilValue asNilValue()
Returns the value asNilValue
. Otherwise throwsMessageTypeCastException
. Note that you can't useinstanceof
or cast((NilValue) thisValue)
to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException
- If type of this value is not Nil.
-
asBooleanValue
BooleanValue asBooleanValue()
Returns the value asBooleanValue
. Otherwise throwsMessageTypeCastException
. Note that you can't useinstanceof
or cast((BooleanValue) thisValue)
to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException
- If type of this value is not Boolean.
-
asNumberValue
NumberValue asNumberValue()
Returns the value asNumberValue
. Otherwise throwsMessageTypeCastException
. Note that you can't useinstanceof
or cast((NumberValue) thisValue)
to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException
- If type of this value is not Integer or Float.
-
asIntegerValue
IntegerValue asIntegerValue()
Returns the value asIntegerValue
. Otherwise throwsMessageTypeCastException
. Note that you can't useinstanceof
or cast((IntegerValue) thisValue)
to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException
- If type of this value is not Integer.
-
asFloatValue
FloatValue asFloatValue()
Returns the value asFloatValue
. Otherwise throwsMessageTypeCastException
. Note that you can't useinstanceof
or cast((FloatValue) thisValue)
to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException
- If type of this value is not Float.
-
asRawValue
RawValue asRawValue()
Returns the value asRawValue
. Otherwise throwsMessageTypeCastException
. Note that you can't useinstanceof
or cast((RawValue) thisValue)
to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException
- If type of this value is not Binary or String.
-
asBinaryValue
BinaryValue asBinaryValue()
Returns the value asBinaryValue
. Otherwise throwsMessageTypeCastException
. Note that you can't useinstanceof
or cast((BinaryValue) thisValue)
to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException
- If type of this value is not Binary.
-
asStringValue
StringValue asStringValue()
Returns the value asStringValue
. Otherwise throwsMessageTypeCastException
. Note that you can't useinstanceof
or cast((StringValue) thisValue)
to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException
- If type of this value is not String.
-
asArrayValue
ArrayValue asArrayValue()
Returns the value asArrayValue
. Otherwise throwsMessageTypeCastException
. Note that you can't useinstanceof
or cast((ArrayValue) thisValue)
to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException
- If type of this value is not Array.
-
asMapValue
MapValue asMapValue()
Returns the value asMapValue
. Otherwise throwsMessageTypeCastException
. Note that you can't useinstanceof
or cast((MapValue) thisValue)
to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException
- If type of this value is not Map.
-
asExtensionValue
ExtensionValue asExtensionValue()
Returns the value asExtensionValue
. Otherwise throwsMessageTypeCastException
. Note that you can't useinstanceof
or cast((ExtensionValue) thisValue)
to check type of a value because type of a mutable value is variable.- Throws:
MessageTypeCastException
- If type of this value is not an Extension.
-
writeTo
void writeTo(MessagePacker pk) throws java.io.IOException
Serializes the value using the specifiedMessagePacker
- Throws:
java.io.IOException
- See Also:
MessagePacker
-
equals
boolean equals(java.lang.Object obj)
Compares this value to the specified object. This method returnstrue
if type and value are equivalent. If this value isMapValue
orArrayValue
, this method check equivalence of elements recursively.- Overrides:
equals
in classjava.lang.Object
-
toJson
java.lang.String toJson()
Returns json representation of this Value.Following behavior is not configurable at this release and they might be changed at future releases:
- if a key of MapValue is not string, the key is converted to a string using toString method.
- NaN and Infinity of DoubleValue are converted to null.
- ExtensionValue is converted to a 2-element array where first element is a number and second element is the data encoded in hex.
- BinaryValue is converted to a string using UTF-8 encoding. Invalid byte sequence is replaced with
U+FFFD replacement character
. - Invalid UTF-8 byte sequences in StringValue is replaced with
U+FFFD replacement character
-
-