ProtobufSerializer implements StreamSerializer<T> { @Nonnull public static <T extends GeneratedMessageV3> ProtobufSerializer<T> from(@Nonnull Class<T> clazz, int typeId) { return new ProtobufSerializer<T>(clazz, typeId) { }; } protected  ProtobufSerializer(@Nonnull Class<T> clazz, int typeId); @Override int getTypeId(); @Override void write(ObjectDataOutput out, T object); @Override T read(ObjectDataInput in); @Nonnull static ProtobufSerializer<T> from(@Nonnull Class<T> clazz, int typeId);  }
@Test public void when_serializes_then_isAbleToDeserialize() { Person original = Person.newBuilder().setName("Joe").setAge(18).build(); StreamSerializer<Person> serializer = ProtobufSerializer.from(Person.class, 1); Person transformed = deserialize(serializer, serialize(serializer, original)); assertThat(transformed).isEqualTo(original); }