-
public interface ValueValue stores a value and its type in MessagePack type system.
Type conversionYou 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 com.batch.android.msgpack.core.MessageTypeCastException.
Immutable interfaceValue 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.
Converting to JSONtoJson 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
Modifier and Type Method Description abstract ValueTypegetValueType()Returns type of this value. abstract ImmutableValueimmutableValue()Returns immutable copy of this value. abstract booleanisNilValue()Returns true if type of this value is Nil. abstract booleanisBooleanValue()Returns true if type of this value is Boolean. abstract booleanisNumberValue()Returns true if type of this value is Integer or Float. abstract booleanisIntegerValue()Returns true if type of this value is Integer. abstract booleanisFloatValue()Returns true if type of this value is Float. abstract booleanisRawValue()Returns true if type of this value is String or Binary. abstract booleanisBinaryValue()Returns true if type of this value is Binary. abstract booleanisStringValue()Returns true if type of this value is String. abstract booleanisArrayValue()Returns true if type of this value is Array. abstract booleanisMapValue()Returns true if type of this value is Map. abstract booleanisExtensionValue()Returns true if type of this an Extension. abstract NilValueasNilValue()Returns the value as {@code NilValue}.abstract BooleanValueasBooleanValue()Returns the value as {@code BooleanValue}.abstract NumberValueasNumberValue()Returns the value as {@code NumberValue}.abstract IntegerValueasIntegerValue()Returns the value as {@code IntegerValue}.abstract FloatValueasFloatValue()Returns the value as {@code FloatValue}.abstract RawValueasRawValue()Returns the value as {@code RawValue}.abstract BinaryValueasBinaryValue()Returns the value as {@code BinaryValue}.abstract StringValueasStringValue()Returns the value as {@code StringValue}.abstract ArrayValueasArrayValue()Returns the value as {@code ArrayValue}.abstract MapValueasMapValue()Returns the value as {@code MapValue}.abstract ExtensionValueasExtensionValue()Returns the value as {@code ExtensionValue}.abstract voidwriteTo(MessagePacker pk)Serializes the value using the specified {@code MessagePacker}abstract booleanequals(Object obj)Compares this value to the specified object. abstract StringtoJson()Returns json representation of this Value. -
-
Method Detail
-
getValueType
abstract ValueType getValueType()
Returns type of this value.
Note that you can't use
instanceofto check type of a value because type of a mutable value is variable.
-
immutableValue
abstract ImmutableValue immutableValue()
Returns immutable copy of this value.
This method simply returns
thiswithout copying the value if this value is already immutable.
-
isNilValue
abstract boolean isNilValue()
Returns true if type of this value is Nil.
If this method returns true,
{@code asNilValue}never throws exceptions.Note that you can't useinstanceofor cast((NilValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isBooleanValue
abstract boolean isBooleanValue()
Returns true if type of this value is Boolean.
If this method returns true,
{@code asBooleanValue}never throws exceptions.Note that you can't useinstanceofor cast((BooleanValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isNumberValue
abstract boolean isNumberValue()
Returns true if type of this value is Integer or Float.
If this method returns true,
{@code asNumberValue}never throws exceptions.Note that you can't useinstanceofor cast((NumberValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isIntegerValue
abstract boolean isIntegerValue()
Returns true if type of this value is Integer.
If this method returns true,
{@code asIntegerValue}never throws exceptions.Note that you can't useinstanceofor cast((IntegerValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isFloatValue
abstract boolean isFloatValue()
Returns true if type of this value is Float.
If this method returns true,
{@code asFloatValue}never throws exceptions.Note that you can't useinstanceofor cast((FloatValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isRawValue
abstract boolean isRawValue()
Returns true if type of this value is String or Binary.
If this method returns true,
{@code asRawValue}never throws exceptions.Note that you can't useinstanceofor cast((RawValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isBinaryValue
abstract boolean isBinaryValue()
Returns true if type of this value is Binary.
If this method returns true,
{@code asBinaryValue}never throws exceptions.Note that you can't useinstanceofor cast((BinaryValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isStringValue
abstract boolean isStringValue()
Returns true if type of this value is String.
If this method returns true,
{@code asStringValue}never throws exceptions.Note that you can't useinstanceofor cast((StringValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isArrayValue
abstract boolean isArrayValue()
Returns true if type of this value is Array.
If this method returns true,
{@code asArrayValue}never throws exceptions.Note that you can't useinstanceofor cast((ArrayValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isMapValue
abstract boolean isMapValue()
Returns true if type of this value is Map.
If this method returns true,
{@code asMapValue}never throws exceptions.Note that you can't useinstanceofor cast((MapValue) thisValue)to check type of a value because type of a mutable value is variable.
-
isExtensionValue
abstract boolean isExtensionValue()
Returns true if type of this an Extension.
If this method returns true,
{@code asExtensionValue}never throws exceptions.Note that you can't useinstanceofor cast((ExtensionValue) thisValue)to check type of a value becausetype of a mutable value is variable.
-
asNilValue
abstract NilValue asNilValue()
Returns the value as
{@code NilValue}. Otherwise throws{@code MessageTypeCastException}.Note that you can't use
instanceofor cast((NilValue) thisValue)to check type of a value because type of a mutable value is variable.
-
asBooleanValue
abstract BooleanValue asBooleanValue()
Returns the value as
{@code BooleanValue}. Otherwise throws{@code MessageTypeCastException}.Note that you can't use
instanceofor cast((BooleanValue) thisValue)to check type of a value because type of a mutable value is variable.
-
asNumberValue
abstract NumberValue asNumberValue()
Returns the value as
{@code NumberValue}. Otherwise throws{@code MessageTypeCastException}.Note that you can't use
instanceofor cast((NumberValue) thisValue)to check type of a value because type of a mutable value is variable.
-
asIntegerValue
abstract IntegerValue asIntegerValue()
Returns the value as
{@code IntegerValue}. Otherwise throws{@code MessageTypeCastException}.Note that you can't use
instanceofor cast((IntegerValue) thisValue)to check type of a value because type of a mutable value is variable.
-
asFloatValue
abstract FloatValue asFloatValue()
Returns the value as
{@code FloatValue}. Otherwise throws{@code MessageTypeCastException}.Note that you can't use
instanceofor cast((FloatValue) thisValue)to check type of a value because type of a mutable value is variable.
-
asRawValue
abstract RawValue asRawValue()
Returns the value as
{@code RawValue}. Otherwise throws{@code MessageTypeCastException}.Note that you can't use
instanceofor cast((RawValue) thisValue)to check type of a value because type of a mutable value is variable.
-
asBinaryValue
abstract BinaryValue asBinaryValue()
Returns the value as
{@code BinaryValue}. Otherwise throws{@code MessageTypeCastException}.Note that you can't use
instanceofor cast((BinaryValue) thisValue)to check type of a value because type of a mutable value is variable.
-
asStringValue
abstract StringValue asStringValue()
Returns the value as
{@code StringValue}. Otherwise throws{@code MessageTypeCastException}.Note that you can't use
instanceofor cast((StringValue) thisValue)to check type of a value because type of a mutable value is variable.
-
asArrayValue
abstract ArrayValue asArrayValue()
Returns the value as
{@code ArrayValue}. Otherwise throws{@code MessageTypeCastException}.Note that you can't use
instanceofor cast((ArrayValue) thisValue)to check type of a value because type of a mutable value is variable.
-
asMapValue
abstract MapValue asMapValue()
Returns the value as
{@code MapValue}. Otherwise throws{@code MessageTypeCastException}.Note that you can't use
instanceofor cast((MapValue) thisValue)to check type of a value because type of a mutable value is variable.
-
asExtensionValue
abstract ExtensionValue asExtensionValue()
Returns the value as
{@code ExtensionValue}. Otherwise throws{@code MessageTypeCastException}.Note that you can't use
instanceofor cast((ExtensionValue) thisValue)to check type of a valuebecause type of a mutable value is variable.
-
writeTo
abstract void writeTo(MessagePacker pk)
Serializes the value using the specified
{@code MessagePacker}
-
equals
abstract boolean equals(Object obj)
Compares this value to the specified object.
This method returns
{@code true}if type and value are equivalent.If this value is{@code MapValue}or{@code ArrayValue}, this method check equivalence of elements recursively.
-
toJson
abstract 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
-
-
-
-