use of com.hazelcast.internal.serialization.PortableContext in project hazelcast by hazelcast.
the class PortableGetter method getValue.
@Override
Object getValue(Object target, String fieldPath) throws Exception {
Data data = (Data) target;
PortableContext context = serializationService.getPortableContext();
PortableReader reader = serializationService.createPortableReader(data);
ClassDefinition classDefinition = context.lookupClassDefinition(data);
FieldDefinition fieldDefinition = context.getFieldDefinition(classDefinition, fieldPath);
if (fieldDefinition != null) {
return ((DefaultPortableReader) reader).read(fieldPath);
} else {
return null;
}
}
use of com.hazelcast.internal.serialization.PortableContext in project hazelcast by hazelcast.
the class PortableTest method testClassDefinitionLookup.
static void testClassDefinitionLookup(InternalSerializationService ss) throws IOException {
NamedPortableV2 p = new NamedPortableV2("test-portable", 123456789, 500);
Data data = ss.toData(p);
PortableContext portableContext = ss.getPortableContext();
ClassDefinition cd = portableContext.lookupClassDefinition(data);
assertNotNull(cd);
assertEquals(p.getFactoryId(), cd.getFactoryId());
assertEquals(p.getClassId(), cd.getClassId());
assertEquals(p.getClassVersion(), cd.getVersion());
}
use of com.hazelcast.internal.serialization.PortableContext in project hazelcast by hazelcast.
the class PortableTest method testClassDefinition_getNestedField.
@Test
public void testClassDefinition_getNestedField() throws IOException {
InternalSerializationService serializationService = new DefaultSerializationServiceBuilder().build();
PortableContext portableContext = serializationService.getPortableContext();
ChildPortableObject child = new ChildPortableObject(System.nanoTime());
ParentPortableObject parent = new ParentPortableObject(System.currentTimeMillis(), child);
GrandParentPortableObject grandParent = new GrandParentPortableObject(System.nanoTime(), parent);
Data data = serializationService.toData(grandParent);
ClassDefinition classDefinition = portableContext.lookupClassDefinition(data);
FieldDefinition fd = portableContext.getFieldDefinition(classDefinition, "child");
assertNotNull(fd);
assertEquals(FieldType.PORTABLE, fd.getType());
fd = portableContext.getFieldDefinition(classDefinition, "child.child");
assertNotNull(fd);
assertEquals(FieldType.PORTABLE, fd.getType());
fd = portableContext.getFieldDefinition(classDefinition, "child.child.timestamp");
assertNotNull(fd);
assertEquals(FieldType.LONG, fd.getType());
}
Aggregations