Class CompactSerializationService
CompactTypeSerializers and
encodes/decodes Compact payloads.
Applications register a serializer per class (rejecting conflicting duplicate registrations),
then call serialize/deserialize to convert instances to and from schema-bound
payloads. serializeRecord(GenericRecord) and deserializeRecord(byte[]) handle
GenericRecords for class-free access, and schemaOf(byte[]) extracts a payload's
CompactSchema. The registry is thread-safe; the same serializers must be installed
consistently across all nodes that read or write a given type.
The public compatibility contract is the schema contract: type name, ordered field names, field kinds, nullability, and the derived fingerprint. Compact bytes are an opaque LoomCache payload; use this service rather than parsing or constructing the private binary layout directly. Changing a type name or field kind is incompatible. Adding fields is compatible only when older readers provide defaults for missing fields; removing fields is compatible only when newer readers no longer require them.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> Tdeserialize(byte[] payload, Class<T> targetType) Deserializes a Compact payload with the serializer registered fortargetType.deserializeRecord(byte[] payload) Decodes a Compact payload as a class-freeGenericRecord.<T> voidregister(CompactTypeSerializer<T> serializer) Registers the serializer for its declared Java type.schemaOf(byte[] payload) Extracts the schema carried by a Compact payload.<T> byte[]serialize(T value) Serializesvalueusing the serializer registered for its runtime class.<T> byte[]Serializesvalueusing the serializer registered forsourceType.byte[]serializeRecord(GenericRecord record) Serializes a class-freeGenericRecordas an opaque Compact payload.
-
Constructor Details
-
CompactSerializationService
public CompactSerializationService()
-
-
Method Details
-
register
Registers the serializer for its declared Java type.All clients and members that exchange the type must register equivalent serializers with the same Compact type name and field contract before writing values that depend on them.
- Type Parameters:
T- application type handled by the serializer- Parameters:
serializer- serializer to register- Throws:
NullPointerException- if the serializer, type, or type name is nullIllegalArgumentException- if the type name is blank or a different serializer is already registered for the same Java class
-
serialize
public <T> byte[] serialize(T value) Serializesvalueusing the serializer registered for its runtime class.- Type Parameters:
T- runtime type of the value- Parameters:
value- non-null value to serialize- Returns:
- opaque Compact payload bytes
- Throws:
SerializationException- if no serializer is registered or the payload is invalid
-
serialize
Serializesvalueusing the serializer registered forsourceType.- Type Parameters:
T- source type- Parameters:
value- non-null value to serializesourceType- registered source type- Returns:
- opaque Compact payload bytes
- Throws:
IllegalArgumentException- ifvalueis not an instance ofsourceTypeSerializationException- if no serializer is registered or the payload is invalid
-
deserialize
Deserializes a Compact payload with the serializer registered fortargetType.- Type Parameters:
T- target type- Parameters:
payload- opaque Compact payload bytestargetType- target Java type- Returns:
- decoded value
- Throws:
SerializationException- if the payload is malformed, no serializer is registered, or the payload type name does not match the target serializer
-
serializeRecord
Serializes a class-freeGenericRecordas an opaque Compact payload.- Parameters:
record- record to serialize- Returns:
- opaque Compact payload bytes
-
deserializeRecord
Decodes a Compact payload as a class-freeGenericRecord.- Parameters:
payload- opaque Compact payload bytes- Returns:
- decoded generic record
- Throws:
SerializationException- if the payload is malformed
-
schemaOf
Extracts the schema carried by a Compact payload.- Parameters:
payload- opaque Compact payload bytes- Returns:
- decoded schema
- Throws:
SerializationException- if the payload is malformed
-