Interface CompactReader
Read operations might throw HazelcastSerializationException
when a
field with the given name is not found or there is a type mismatch.
The way to use CompactReader
for class evolution is to check for the
existence of a field with its name and kind, with the
getFieldKind(String)
method. One should read the field if it exists
with the given name and kind, and use some other logic, like using a default
value, if it does not exist.
public Foo read(CompactReader reader) {
int bar = reader.readInt32("bar"); // A field that is always present
String baz;
if (reader.getFieldKind("baz") == FieldKind.STRING) {
baz = reader.readString("baz");
} else {
baz = ""; // Use a default value, if the field is not present
}
return new Foo(bar, baz);
}
- Since:
- 5.2
-
Method Summary
Modifier and TypeMethodDescriptiongetFieldKind
(String fieldName) Returns the kind of the field for the given field name.boolean[]
readArrayOfBoolean
(String fieldName) Reads an array of booleans.<T> T[]
readArrayOfCompact
(String fieldName, Class<T> componentType) Reads an array of compact objects.readArrayOfDate
(String fieldName) Reads an array of dates consisting of year, month, and day.readArrayOfDecimal
(String fieldName) Reads an array of arbitrary precision and scale floating point numbers.float[]
readArrayOfFloat32
(String fieldName) Reads an array of 32-bit IEEE 754 floating point numbers.double[]
readArrayOfFloat64
(String fieldName) Reads an array of 64-bit IEEE 754 floating point numbers.short[]
readArrayOfInt16
(String fieldName) Reads an array of 16-bit two's complement signed integers.int[]
readArrayOfInt32
(String fieldName) Reads an array of 32-bit two's complement signed integers.long[]
readArrayOfInt64
(String fieldName) Reads an array of 64-bit two's complement signed integers.byte[]
readArrayOfInt8
(String fieldName) Reads an array of 8-bit two's complement signed integers.Boolean[]
readArrayOfNullableBoolean
(String fieldName) Reads a nullable array of nullable booleans.Float[]
readArrayOfNullableFloat32
(String fieldName) Reads a nullable array of nullable 32-bit IEEE 754 floating point numbers.Double[]
readArrayOfNullableFloat64
(String fieldName) Reads a nullable array of nullable 64-bit IEEE 754 floating point numbers.Short[]
readArrayOfNullableInt16
(String fieldName) Reads a nullable array of nullable 16-bit two's complement signed integers.Integer[]
readArrayOfNullableInt32
(String fieldName) Reads a nullable array of nullable 32-bit two's complement signed integers.Long[]
readArrayOfNullableInt64
(String fieldName) Reads a nullable array of nullable 64-bit two's complement signed integers.Byte[]
readArrayOfNullableInt8
(String fieldName) Reads a nullable array of nullable 8-bit two's complement signed integers.String[]
readArrayOfString
(String fieldName) Reads an array of UTF-8 encoded strings.readArrayOfTime
(String fieldName) Reads an array of times consisting of hour, minute, second, and nanosecondsreadArrayOfTimestamp
(String fieldName) Reads an array of timestamps consisting of date and time.readArrayOfTimestampWithTimezone
(String fieldName) Reads an array of timestamps with timezone consisting of date, time and timezone offset.boolean
readBoolean
(String fieldName) Reads a boolean.<T> T
readCompact
(String fieldName) Reads a compact objectReads a date consisting of year, month, and day.readDecimal
(String fieldName) Reads an arbitrary precision and scale floating point number.float
readFloat32
(String fieldName) Reads a 32-bit IEEE 754 floating point number.double
readFloat64
(String fieldName) Reads a 64-bit IEEE 754 floating point number.short
Reads a 16-bit two's complement signed integer.int
Reads a 32-bit two's complement signed integer.long
Reads a 64-bit two's complement signed integer.byte
Reads an 8-bit two's complement signed integer.readNullableBoolean
(String fieldName) Reads a nullable boolean.readNullableFloat32
(String fieldName) Reads a nullable 32-bit IEEE 754 floating point number.readNullableFloat64
(String fieldName) Reads a nullable 64-bit IEEE 754 floating point number.readNullableInt16
(String fieldName) Reads a nullable 16-bit two's complement signed integer.readNullableInt32
(String fieldName) Reads a nullable 32-bit two's complement signed integer.readNullableInt64
(String fieldName) Reads a nullable 64-bit two's complement signed integer.readNullableInt8
(String fieldName) Reads a nullable 8-bit two's complement signed integer.readString
(String fieldName) Reads a UTF-8 encoded string.Reads a time consisting of hour, minute, second, and nanoseconds.readTimestamp
(String fieldName) Reads a timestamp consisting of date and time.readTimestampWithTimezone
(String fieldName) Reads a timestamp with timezone consisting of date, time and timezone offset.
-
Method Details
-
getFieldKind
Returns the kind of the field for the given field name.If the field with the given name does not exist,
FieldKind.NOT_AVAILABLE
is returned.This method can be used to check the existence of a field, which can be useful when the class is evolved.
- Parameters:
fieldName
- name of the field.- Returns:
- kind of the field
-
readBoolean
Reads a boolean.This method can also read a nullable boolean, as long as it is not
null
. If anull
value is read with this method,HazelcastSerializationException
is thrown.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readInt8
Reads an 8-bit two's complement signed integer.This method can also read a nullable int8, as long as it is not
null
. If anull
value is read with this method,HazelcastSerializationException
is thrown.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readInt16
Reads a 16-bit two's complement signed integer.This method can also read a nullable int16, as long as it is not
null
. If anull
value is read with this method,HazelcastSerializationException
is thrown.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readInt32
Reads a 32-bit two's complement signed integer.This method can also read a nullable int32, as long as it is not
null
. If anull
value is read with this method,HazelcastSerializationException
is thrown.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readInt64
Reads a 64-bit two's complement signed integer.This method can also read a nullable int64, as long as it is not
null
. If anull
value is read with this method,HazelcastSerializationException
is thrown.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readFloat32
Reads a 32-bit IEEE 754 floating point number.This method can also read a nullable float32, as long as it is not
null
. If anull
value is read with this method,HazelcastSerializationException
is thrown.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readFloat64
Reads a 64-bit IEEE 754 floating point number.This method can also read a nullable float64, as long as it is not
null
. If anull
value is read with this method,HazelcastSerializationException
is thrown.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readString
Reads a UTF-8 encoded string.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readDecimal
Reads an arbitrary precision and scale floating point number.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readTime
Reads a time consisting of hour, minute, second, and nanoseconds.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readDate
Reads a date consisting of year, month, and day.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readTimestamp
Reads a timestamp consisting of date and time.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readTimestampWithTimezone
Reads a timestamp with timezone consisting of date, time and timezone offset.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readCompact
Reads a compact object- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.HazelcastException
- if the object cannot be created.
-
readArrayOfBoolean
Reads an array of booleans.This method can also read an array of nullable booleans, as long as it does not contain
null
values. If anull
array item is read with this method,HazelcastSerializationException
is thrown.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfInt8
Reads an array of 8-bit two's complement signed integers.This method can also read an array of nullable int8s, as long as it does not contain
null
values. If anull
array item is read with this method,HazelcastSerializationException
is thrown.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfInt16
Reads an array of 16-bit two's complement signed integers.This method can also read an array of nullable int16s, as long as it does not contain
null
values. If anull
array item is read with this method,HazelcastSerializationException
is thrown.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfInt32
Reads an array of 32-bit two's complement signed integers.This method can also read an array of nullable int32s, as long as it does not contain
null
values. If anull
array item is read with this method,HazelcastSerializationException
is thrown.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfInt64
Reads an array of 64-bit two's complement signed integers.This method can also read an array of nullable int64s, as long as it does not contain
null
values. If anull
array item is read with this method,HazelcastSerializationException
is thrown.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfFloat32
Reads an array of 32-bit IEEE 754 floating point numbers.This method can also read an array of nullable float32s, as long as it does not contain
null
values. If anull
array item is read with this method,HazelcastSerializationException
is thrown.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfFloat64
Reads an array of 64-bit IEEE 754 floating point numbers.This method can also read an array of nullable float64s, as long as it does not contain
null
values. If anull
array item is read with this method,HazelcastSerializationException
is thrown.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfString
Reads an array of UTF-8 encoded strings.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfDecimal
Reads an array of arbitrary precision and scale floating point numbers.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfTime
Reads an array of times consisting of hour, minute, second, and nanoseconds- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field. The items in the array cannot be null.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfDate
Reads an array of dates consisting of year, month, and day.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field. The items in the array cannot be null.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfTimestamp
Reads an array of timestamps consisting of date and time.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field. The items in the array cannot be null.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfTimestampWithTimezone
Reads an array of timestamps with timezone consisting of date, time and timezone offset.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field. The items in the array cannot be null.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfCompact
Reads an array of compact objects.- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readNullableBoolean
Reads a nullable boolean.This method can also read a non-nullable boolean.
- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readNullableInt8
Reads a nullable 8-bit two's complement signed integer.This method can also read a non-nullable int8.
- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readNullableInt16
Reads a nullable 16-bit two's complement signed integer.This method can also read a non-nullable int16.
- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readNullableInt32
Reads a nullable 32-bit two's complement signed integer.This method can also read a non-nullable int32.
- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readNullableInt64
Reads a nullable 64-bit two's complement signed integer.This method can also read a non-nullable int64.
- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readNullableFloat32
Reads a nullable 32-bit IEEE 754 floating point number.This method can also read a non-nullable float32.
- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readNullableFloat64
Reads a nullable 64-bit IEEE 754 floating point number.This method can also read a non-nullable float64.
- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfNullableBoolean
Reads a nullable array of nullable booleans.This method can also read array of non-nullable booleans.
- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfNullableInt8
Reads a nullable array of nullable 8-bit two's complement signed integers.This method can also read array of non-nullable int8s.
- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfNullableInt16
Reads a nullable array of nullable 16-bit two's complement signed integers.This method can also read array of non-nullable int16s.
- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfNullableInt32
Reads a nullable array of nullable 32-bit two's complement signed integers.This method can also read array of non-nullable int32s.
- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfNullableInt64
Reads a nullable array of nullable 64-bit two's complement signed integers.This method can also read array of non-nullable int64s.
- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfNullableFloat32
Reads a nullable array of nullable 32-bit IEEE 754 floating point numbers.This method can also read array of non-nullable float32s.
- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-
readArrayOfNullableFloat64
Reads a nullable array of nullable 64-bit IEEE 754 floating point numbers.This method can also read array of non-nullable float64s.
- Parameters:
fieldName
- name of the field.- Returns:
- the value of the field.
- Throws:
HazelcastSerializationException
- if the field does not exist in the schema or the type of the field does not match with the one defined in the schema.
-