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));
}
Aggregations