Search in sources :

Example 1 with MessageMarshaller

use of org.infinispan.protostream.MessageMarshaller 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

MessageMarshaller (org.infinispan.protostream.MessageMarshaller)1 SerializationContext (org.infinispan.protostream.SerializationContext)1 User (org.infinispan.protostream.domain.User)1 AbstractProtoStreamTest (org.infinispan.protostream.test.AbstractProtoStreamTest)1 Test (org.junit.Test)1