Search in sources :

Example 1 with ExternalizableEmployeeDTO

use of example.serialization.ExternalizableEmployeeDTO in project hazelcast by hazelcast.

the class CompactStreamSerializerTest method testOverridesJavaSerializationWhenRegisteredAsReflectivelySerializable.

@Test
public void testOverridesJavaSerializationWhenRegisteredAsReflectivelySerializable() {
    SerializationConfig serializationConfig = new SerializationConfig();
    serializationConfig.getCompactSerializationConfig().setEnabled(true).register(ExternalizableEmployeeDTO.class);
    SerializationService serializationService = new DefaultSerializationServiceBuilder().setSchemaService(schemaService).setConfig(serializationConfig).build();
    ExternalizableEmployeeDTO employeeDTO = new ExternalizableEmployeeDTO(30, "John Doe");
    Data data = serializationService.toData(employeeDTO);
    assertFalse(employeeDTO.usedExternalizableSerialization());
    Object object = serializationService.toObject(data);
    ExternalizableEmployeeDTO actual = (ExternalizableEmployeeDTO) object;
    assertFalse(employeeDTO.usedExternalizableSerialization());
    assertEquals(employeeDTO, actual);
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) ExternalizableEmployeeDTO(example.serialization.ExternalizableEmployeeDTO) SerializationConfig(com.hazelcast.config.SerializationConfig) CompactSerializationConfig(com.hazelcast.config.CompactSerializationConfig) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with ExternalizableEmployeeDTO

use of example.serialization.ExternalizableEmployeeDTO in project hazelcast by hazelcast.

the class CompactTestUtil method verifyReflectiveSerializerIsUsed.

public static void verifyReflectiveSerializerIsUsed(SerializationConfig serializationConfig) {
    SerializationService serializationService = new DefaultSerializationServiceBuilder().setSchemaService(CompactTestUtil.createInMemorySchemaService()).setConfig(serializationConfig).build();
    ExternalizableEmployeeDTO object = new ExternalizableEmployeeDTO();
    Data data = serializationService.toData(object);
    assertFalse(object.usedExternalizableSerialization());
    ExternalizableEmployeeDTO deserializedObject = serializationService.toObject(data);
    assertFalse(deserializedObject.usedExternalizableSerialization());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) ExternalizableEmployeeDTO(example.serialization.ExternalizableEmployeeDTO) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data)

Aggregations

Data (com.hazelcast.internal.serialization.Data)2 SerializationService (com.hazelcast.internal.serialization.SerializationService)2 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)2 ExternalizableEmployeeDTO (example.serialization.ExternalizableEmployeeDTO)2 CompactSerializationConfig (com.hazelcast.config.CompactSerializationConfig)1 SerializationConfig (com.hazelcast.config.SerializationConfig)1 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1