Uploaded image for project: 'Infinispan'
  1. Infinispan
  2. ISPN-12626

Document @ProtoAdaptor for marshalling of external classes

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Done
    • Icon: Major Major
    • 12.0.0.Final
    • 12.0.0.CR1
    • Documentation
    • None

      Protostream 4.4.0.Alpha4 added support for automatically generating marshallers for external classes via the @ProtoAdaptor field. This greatly simplifies how a user can marshall third party classes, as it's no longer necessary to implement the MessageMarshaller interface and explicitly create a SerializationContextInitializer implementation.

      Process for using @ProtoAdaptor
      1. Create an adaptor class and add the @ProtoAdaptor annotation

      @ProtoAdapter(UUID.class)
      public class UUIDAdapter {
      
         @ProtoFactory
         UUID create(Long mostSigBitsFixed, Long leastSigBitsFixed) {
               return new UUID(mostSigBitsFixed, leastSigBitsFixed);
         }
      
         @ProtoField(number = 1, type = Type.FIXED64, defaultValue = "0")
         Long getMostSigBitsFixed(UUID uuid) {
            return uuid.getMostSignificantBits();
         }
      
         @ProtoField(number = 2, type = Type.FIXED64, defaultValue = "0")
         Long getLeastSigBitsFixed(UUID uuid) {
            return uuid.getLeastSignificantBits();
         }
      }
      

      2. Register UUIDAdapter with your SerialiazationContextInitializer interface (LibraryInitializer in the docs examples).

            dnaro@redhat.com Donald Naro
            remerson@redhat.com Ryan Emerson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: