Class ProtoSerializerBuilder

java.lang.Object
com.inductiveautomation.ignition.common.rpc.proto.ProtoSerializerBuilder

public final class ProtoSerializerBuilder extends Object
A builder for creating a ProtoRpcSerializer.

By default, is able to serialize base Java primitives (upcasting smaller numbers to integer), core Java classes such as UUID, Date, and Locale, and some of the most fundamental Ignition classes, such as NamedQuery and BasicQualifiedValue.

Additional serializers should be registered as needed for specific use cases. To do so,

  1. Choose a representation format (binary, 'composite', or 'sequence').
  2. Add an appropriate 'adapter' for that format that will handle serialization and deserialization.
  3. Ensure both sides of your RPC handshake are using an appropriately set up serializer.
See Also:
  • Method Details

    • addBinaryAdapter

      public <T> ProtoSerializerBuilder addBinaryAdapter(Class<T> clazz, BinarySerializer<T> serializer, BinaryDeserializer<T> deserializer)
      Registers an adapter capable of serializing and deserializing objects of the given class. This is the most flexible serialization method, as it allows for custom serialization and deserialization logic - you only need to provide your own logic to marshal to and from bytes.
    • addBinaryAdapter

      public <T> ProtoSerializerBuilder addBinaryAdapter(Class<T> clazz, BinaryAdapter<T> adapter)
      Registers an adapter capable of serializing and deserializing objects of the given class. This is the most flexible serialization method, as it allows for custom serialization and deserialization logic - you only need to provide your own logic to marshal to and from bytes.
      Parameters:
      clazz - the class this serializer pair works for. the class name is used as the identifier.
    • addAdapter

      public <T> ProtoSerializerBuilder addAdapter(Class<T> clazz, ValueSerializer<T> serializer, ValueDeserializer<T> deserializer)
      Registers an adapter capable of serializing and deserializing objects of the given class.
    • addAdapter

      public <T> ProtoSerializerBuilder addAdapter(Class<T> clazz, ValueAdapter<T> adapter)
    • addGsonAdapter

      public <T, S extends com.inductiveautomation.ignition.common.gson.JsonSerializer<T> & com.inductiveautomation.ignition.common.gson.JsonDeserializer<T>> ProtoSerializerBuilder addGsonAdapter(Class<T> clazz, S adapter)
      Registers an adapter capable of serializing and deserializing objects of the given class. This method will use the internal Gson instance to serialize and deserialize objects.
    • addProtoAdapter

      public <T, S extends com.google.protobuf.Message> ProtoSerializerBuilder addProtoAdapter(Class<T> clazz, FragileFunction<byte[],S,com.google.protobuf.InvalidProtocolBufferException> protoDeserializer, FragileFunction<T,S,Exception> serializer, FragileFunction<S,T,Exception> deserializer)
    • customizeGson

      public ProtoSerializerBuilder customizeGson(Consumer<com.inductiveautomation.ignition.common.gson.GsonBuilder> customizer)
    • withFallbackSerializationStrategy

      public ProtoSerializerBuilder withFallbackSerializationStrategy(ValueAdapter<?> adapter)
      By default, the constructed serializer will fall back to a GSON reflection based approach to serialize values without more specific adapters registered. If you want to use a different approach, you can do so by providing serialization and deserialization methods appropriately.
    • build

      public ProtoRpcSerializer build()