@Beta public interface GenericRecord
IMap
,IQueue
etc.
On remote calls like distributed executor service or EntryProcessors, you may need to access to the domain object. In case class of the domain object is not available on the cluster, GenericRecord allows to access, read and write the objects back without the class of the domain object on the classpath. Here is an read example with EntryProcessor:
map.executeOnKey(key, (EntryProcessorAnother example with EntryProcessor to demonstrate how to read, modify and set back to the map:
map.executeOnKey("key", (EntryProcessor
GenericRecord also allows to read from a cluster without having the classes on the client side.
For Portable
, when PortableFactory
is not provided in the config at the start,
a HazelcastSerializationException
was thrown stating that a factory could not be found. Starting from 4.1,
the objects will be returned as GenericRecord
. This way, the clients can be read and write the objects back to
the cluster without needing the classes of the domain objects on the classpath.
Currently this is valid for Portable
objects.
Modifier and Type | Interface and Description |
---|---|
static interface |
GenericRecord.Builder
Interface for creating
GenericRecord instances. |
Modifier and Type | Method and Description |
---|---|
GenericRecord.Builder |
cloneWithBuilder()
Returned
GenericRecord.Builder can be used to have exact copy and also just to update a couple of fields. |
Set<String> |
getFieldNames() |
FieldType |
getFieldType(String fieldName) |
boolean |
hasField(String fieldName) |
GenericRecord.Builder |
newBuilder()
Creates a
GenericRecord.Builder allows to create a new object. |
boolean |
readBoolean(String fieldName) |
boolean[] |
readBooleanArray(String fieldName) |
byte |
readByte(String fieldName) |
byte[] |
readByteArray(String fieldName) |
char |
readChar(String fieldName) |
char[] |
readCharArray(String fieldName) |
double |
readDouble(String fieldName) |
double[] |
readDoubleArray(String fieldName) |
float |
readFloat(String fieldName) |
float[] |
readFloatArray(String fieldName) |
GenericRecord |
readGenericRecord(String fieldName) |
GenericRecord[] |
readGenericRecordArray(String fieldName) |
int |
readInt(String fieldName) |
int[] |
readIntArray(String fieldName) |
long |
readLong(String fieldName) |
long[] |
readLongArray(String fieldName) |
short |
readShort(String fieldName) |
short[] |
readShortArray(String fieldName) |
String |
readUTF(String fieldName) |
String[] |
readUTFArray(String fieldName) |
@Nonnull GenericRecord.Builder newBuilder()
GenericRecord.Builder
allows to create a new object. This method is a convenience method to get a builder,
without creating the class definition for this type. Here you can see a new object is constructed from an existing
GenericRecord with its class definition:
GenericRecord newGenericRecord = genericRecord.newBuilder() .writeUTF("name", "bar") .writeInt("id", 4).build();
see GenericRecord.Builder.portable(ClassDefinition)
to create a GenericRecord in Portable format
with a different class definition.
@Nonnull GenericRecord.Builder cloneWithBuilder()
GenericRecord.Builder
can be used to have exact copy and also just to update a couple of fields. By default,
it will copy all the fields.
So instead of following where only the `id` field is updated,
GenericRecord modifiedGenericRecord = genericRecord.newBuilder() .writeUTF("name", genericRecord.readUTF("name")) .writeLong("id", 4) .writeUTF("surname", genericRecord.readUTF("surname")) .writeInt("age", genericRecord.readInt("age")).build();`cloneWithBuilder` used as follows:
GenericRecord modifiedGenericRecord = genericRecord.cloneWithBuilder().writeInt("id", 4).build();
@Nonnull Set<String> getFieldNames()
@Nonnull FieldType getFieldType(@Nonnull String fieldName)
fieldName
- the name of the fieldIllegalArgumentException
- if the field name does not exist in the class definitionboolean hasField(@Nonnull String fieldName)
fieldName
- the name of the fieldboolean readBoolean(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.byte readByte(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.char readChar(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.double readDouble(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.float readFloat(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.int readInt(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.long readLong(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.short readShort(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.@Nullable String readUTF(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.@Nullable GenericRecord readGenericRecord(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.@Nullable boolean[] readBooleanArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.@Nullable byte[] readByteArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.@Nullable char[] readCharArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.@Nullable double[] readDoubleArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.@Nullable float[] readFloatArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.@Nullable int[] readIntArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.@Nullable long[] readLongArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.@Nullable short[] readShortArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.@Nullable String[] readUTFArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.@Nullable GenericRecord[] readGenericRecordArray(@Nonnull String fieldName)
fieldName
- the name of the fieldHazelcastSerializationException
- if the field name does not exist in the class definition or
the type of the field does not match the one in the class definition.Copyright © 2022 Hazelcast, Inc.. All rights reserved.