Search in sources :

Example 1 with PortableContext

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;
    }
}
Also used : DefaultPortableReader(com.hazelcast.internal.serialization.impl.DefaultPortableReader) FieldDefinition(com.hazelcast.nio.serialization.FieldDefinition) PortableContext(com.hazelcast.internal.serialization.PortableContext) Data(com.hazelcast.nio.serialization.Data) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) DefaultPortableReader(com.hazelcast.internal.serialization.impl.DefaultPortableReader) PortableReader(com.hazelcast.nio.serialization.PortableReader)

Example 2 with PortableContext

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());
}
Also used : PortableContext(com.hazelcast.internal.serialization.PortableContext)

Example 3 with PortableContext

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());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) PortableContext(com.hazelcast.internal.serialization.PortableContext) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

PortableContext (com.hazelcast.internal.serialization.PortableContext)3 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 DefaultPortableReader (com.hazelcast.internal.serialization.impl.DefaultPortableReader)1 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)1 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)1 Data (com.hazelcast.nio.serialization.Data)1 FieldDefinition (com.hazelcast.nio.serialization.FieldDefinition)1 PortableReader (com.hazelcast.nio.serialization.PortableReader)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1