Serialization Schemes #
Every entity attribute in Proxima declares a serialization scheme URI. The scheme tells Repository how to map attribute payloads between strongly-typed Java objects and raw byte[] arrays for storage, network transport, JSON rendering, and Parquet/schema projection.
How Schemes Work #
In HOCON configuration, an attribute’s scheme field is a URI whose scheme prefix is matched against registered
ValueSerializerFactory implementations discovered via Java’s ServiceLoader:
entities {
user {
attributes {
details { scheme: "proto:cz.o2.proxima.example.user.User$Details" }
age { scheme: "integer" }
nickname { scheme: "string" }
}
}
}
When Repository.of(config) runs with Validate.SERIALIZERS enabled (the default), Proxima resolves each attribute’s
ValueSerializer and verifies isUsable() at startup so misconfigured classes or missing modules fail fast.
Built-in Schemes (proxima-core)
#
These schemes are available out of the box with no extra dependencies beyond proxima-core:
| Scheme | Java Type | Wire Format | Default Value | Notes |
|---|---|---|---|---|
bytes | byte[] | Raw bytes (Base64 in JSON) | new byte[0] | No schema validation; useful for opaque binary payloads. |
string | String | UTF-8 bytes | "" | Standard text values. |
integer | Integer | 4-byte big-endian ByteBuffer | 0 | Signed 32-bit integer. |
long | Long | 8-byte big-endian ByteBuffer | 0L | Signed 64-bit integer. |
float | Float | 4-byte IEEE 754 big-endian | 0.0f | 32-bit floating point. |
double | Double | 8-byte IEEE 754 big-endian | 0.0d | 64-bit floating point. |
json | String | Raw UTF-8 JSON string | "{}" | @Experimental; passes JSON text through without parsing. |
java:<ClassName> | <ClassName> | Standard Java ObjectOutputStream | Default no-arg instance | Class must implement Serializable and have a public no-arg constructor. Shorthand like java:String resolves java.lang.*. Avoid in production due to performance and schema-evolution limitations. |
Example using built-in schemes:
entities {
sensor {
attributes {
label { scheme: "string" }
reading { scheme: "double" }
counter { scheme: "long" }
rawPayload { scheme: "bytes" }
metadata { scheme: "json" }
}
}
}
Extension Scheme Modules #
For structured, evolvable domain models, add one of the dedicated scheme modules to your classpath.
Protocol Buffers (proto: and json-proto:)
#
Module: cz.o2.proxima:proxima-scheme-proto
Protocol Buffers is the primary structured serialization format in Proxima.
Binary Protobuf (proto:)
#
- URI Format:
proto:<Fully.Qualified.Class.Name>(use$for nested Java classes, e.g.,proto:cz.o2.proxima.example.user.User$Details) - Requirements: Generated by
protocand extendingcom.google.protobuf.AbstractMessage. - Capabilities:
- Compact binary wire format with forward/backward schema evolution
- Automatic
asJsonValue/fromJsonValueconversion via protobufJsonFormat - Rich
SchemaTypeDescriptorandAttributeValueAccessorsupport (enables Parquet bulk storage and Beam schema coders) - Built-in transaction metadata serializer (
TransactionSerializerSchemeProvider) for ACID transactions
entities {
user {
attributes {
details { scheme: "proto:cz.o2.proxima.example.user.User$Details" }
}
}
}
JSON-Encoded Protobuf (json-proto:)
#
proxima-scheme-proto also registers JsonProtoSerializerFactory for the json-proto: scheme. It stores UTF-8 JSON on the wire while exposing strongly-typed Protobuf Message objects in Java!
- URI Format:
json-proto:<Fully.Qualified.Class.Name>[?strictScheme=true] - Behavior: By default (
strictScheme=false), unknown JSON fields not present in the.protodefinition are ignored during deserialization. Set?strictScheme=trueto reject payloads containing unknown fields.
entities {
webhook {
attributes {
payload { scheme: "json-proto:cz.o2.proxima.example.WebhookPayload" }
}
}
}
Apache Avro (avro:)
#
Module: cz.o2.proxima:proxima-scheme-avro
Serializes Avro SpecificRecord classes into compact Avro binary format.
- URI Format:
avro:<Fully.Qualified.Class.Name> - Requirements: Generated Avro class implementing
org.apache.avro.specific.SpecificRecordwith a public no-arg constructor andgetSchema(). - Tip: Prefer nullable/optional fields with defaults in your
.avscschemas sogetDefault()round-trips cleanly duringisUsable()validation.
entities {
click {
attributes {
data { scheme: "avro:cz.o2.proxima.example.avro.ClickEvent" }
}
}
}
Confluent Schema Registry (schema-registry:)
#
Module: cz.o2.proxima:proxima-scheme-confluent
Integrates Avro serialization with the Confluent Schema Registry wire format (0x00 magic byte + 4-byte big-endian schema ID + Avro binary payload).
- URI Format:
schema-registry:<registry-base-url>/<subject-name> - Example:
schema-registry:http://schema-registry:8081/user-events-value - Requirements: The corresponding Avro
SpecificRecordclass must be available on the classpath, and the Schema Registry endpoint must be reachable when initializing the serializer.
entities {
event {
attributes {
data { scheme: "schema-registry:http://schema-registry:8081/event" }
}
}
}
Implementing a Custom Scheme #
To add support for a custom format (such as MessagePack, CBOR, Thrift, or Jackson-backed POJOs):
- Implement
ValueSerializerFactoryandValueSerializer<T>. - Register the factory as a
ServiceLoaderprovider (using@AutoService(ValueSerializerFactory.class)or manually viaMETA-INF/services/cz.o2.proxima.core.scheme.ValueSerializerFactory).
package com.example.proxima;
import com.google.auto.service.AutoService;
import cz.o2.proxima.core.scheme.ValueSerializer;
import cz.o2.proxima.core.scheme.ValueSerializerFactory;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
@AutoService(ValueSerializerFactory.class)
public class UuidSerializerFactory implements ValueSerializerFactory {
private static final long serialVersionUID = 1L;
@Override
public String getAcceptableScheme() {
return "uuid";
}
@SuppressWarnings("unchecked")
@Override
public <T> ValueSerializer<T> getValueSerializer(URI specifier) {
return (ValueSerializer<T>) new ValueSerializer<java.util.UUID>() {
private static final long serialVersionUID = 1L;
@Override
public Optional<java.util.UUID> deserialize(byte[] input) {
try {
return Optional.of(java.util.UUID.fromString(new String(input, StandardCharsets.UTF_8)));
} catch (IllegalArgumentException ex) {
return Optional.empty();
}
}
@Override
public byte[] serialize(java.util.UUID value) {
return value.toString().getBytes(StandardCharsets.UTF_8);
}
@Override
public java.util.UUID getDefault() {
return new java.util.UUID(0L, 0L);
}
};
}
@Override
public String getClassName(URI specifier) {
return java.util.UUID.class.getName();
}
}
With the JAR on your classpath, you can immediately declare scheme: "uuid" in your HOCON configuration, and the
Code generator will generate strongly-typed Regular<java.util.UUID> / Wildcard<java.util.UUID> descriptors.