Serialization Schemes

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:

SchemeJava TypeWire FormatDefault ValueNotes
bytesbyte[]Raw bytes (Base64 in JSON)new byte[0]No schema validation; useful for opaque binary payloads.
stringStringUTF-8 bytes""Standard text values.
integerInteger4-byte big-endian ByteBuffer0Signed 32-bit integer.
longLong8-byte big-endian ByteBuffer0LSigned 64-bit integer.
floatFloat4-byte IEEE 754 big-endian0.0f32-bit floating point.
doubleDouble8-byte IEEE 754 big-endian0.0d64-bit floating point.
jsonStringRaw UTF-8 JSON string"{}"@Experimental; passes JSON text through without parsing.
java:<ClassName><ClassName>Standard Java ObjectOutputStreamDefault no-arg instanceClass 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 protoc and extending com.google.protobuf.AbstractMessage.
  • Capabilities:
    • Compact binary wire format with forward/backward schema evolution
    • Automatic asJsonValue / fromJsonValue conversion via protobuf JsonFormat
    • Rich SchemaTypeDescriptor and AttributeValueAccessor support (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 .proto definition are ignored during deserialization. Set ?strictScheme=true to 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.SpecificRecord with a public no-arg constructor and getSchema().
  • Tip: Prefer nullable/optional fields with defaults in your .avsc schemas so getDefault() round-trips cleanly during isUsable() 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 SpecificRecord class 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):

  1. Implement ValueSerializerFactory and ValueSerializer<T>.
  2. Register the factory as a ServiceLoader provider (using @AutoService(ValueSerializerFactory.class) or manually via META-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.