Search in sources :

Example 21 with User

use of org.infinispan.protostream.domain.User in project protostream by infinispan.

the class ProtoSchemaBuilderTest method testReplaceExistingMarshaller.

@Test
public void testReplaceExistingMarshaller() throws Exception {
    SerializationContext ctx = createContext();
    assertTrue(ctx.canMarshall("sample_bank_account.User"));
    assertTrue(ctx.canMarshall(org.infinispan.protostream.domain.User.class));
    MessageMarshaller<AnotherUser> anotherUserMarshaller = new MessageMarshaller<AnotherUser>() {

        @Override
        public AnotherUser readFrom(ProtoStreamReader reader) throws IOException {
            int gender = reader.readInt("gender");
            AnotherUser anotherUser = new AnotherUser();
            anotherUser.gender = (byte) gender;
            return anotherUser;
        }

        @Override
        public void writeTo(ProtoStreamWriter writer, AnotherUser user) throws IOException {
            writer.writeInt("gender", user.gender);
        }

        @Override
        public String getTypeName() {
            return "sample_bank_account.User";
        }

        @Override
        public Class<AnotherUser> getJavaClass() {
            return AnotherUser.class;
        }
    };
    ctx.registerMarshaller(anotherUserMarshaller);
    assertTrue(ctx.canMarshall("sample_bank_account.User"));
    assertTrue(ctx.canMarshall(AnotherUser.class));
    assertFalse(ctx.canMarshall(org.infinispan.protostream.domain.User.class));
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) User(org.infinispan.protostream.domain.User) MessageMarshaller(org.infinispan.protostream.MessageMarshaller) Test(org.junit.Test) AbstractProtoStreamTest(org.infinispan.protostream.test.AbstractProtoStreamTest)

Aggregations

User (org.infinispan.protostream.domain.User)21 Test (org.junit.Test)15 Address (org.infinispan.protostream.domain.Address)12 AbstractProtoStreamTest (org.infinispan.protostream.test.AbstractProtoStreamTest)11 ArrayList (java.util.ArrayList)3 Date (java.util.Date)2 SerializationContext (org.infinispan.protostream.SerializationContext)2 Descriptor (org.infinispan.protostream.descriptors.Descriptor)2 FieldDescriptor (org.infinispan.protostream.descriptors.FieldDescriptor)2 Note (org.infinispan.protostream.domain.Note)2 IOException (java.io.IOException)1 Instant (java.time.Instant)1 List (java.util.List)1 ImmutableSerializationContext (org.infinispan.protostream.ImmutableSerializationContext)1 MessageMarshaller (org.infinispan.protostream.MessageMarshaller)1 Configuration (org.infinispan.protostream.config.Configuration)1 EnumDescriptor (org.infinispan.protostream.descriptors.EnumDescriptor)1 GenericDescriptor (org.infinispan.protostream.descriptors.GenericDescriptor)1 Account (org.infinispan.protostream.domain.Account)1