@Test
public void testCustomIdMapper() throws Exception {
BinaryTypeConfiguration type =
new BinaryTypeConfiguration(CustomMappedObject1.class.getName());
type.setIdMapper(new BinaryIdMapper() {
@Override public int typeId(String clsName) {
return 11111;
}
@Override public int fieldId(int typeId, String fieldName) {
assert typeId == 11111;
if ("val1".equals(fieldName))
return 22222;
else if ("val2".equals(fieldName))
return 33333;
assert false : "Unknown field: " + fieldName;
return 0;
}
});
BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(type));
CustomMappedObject1 obj1 = new CustomMappedObject1(10, "str");
BinaryObjectExImpl po1 = marshal(obj1, marsh);
assertEquals(11111, po1.type().typeId());
assertEquals((Integer)10, po1.field(22222));
assertEquals("str", po1.field(33333));
assertEquals(10, po1.<CustomMappedObject1>deserialize().val1);
assertEquals("str", po1.<CustomMappedObject1>deserialize().val2);
}