use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class GenericRecordTest method testGenericRecordToStringValidJson.
@Test
public void testGenericRecordToStringValidJson() throws IOException {
CompactSerializationConfig compactSerializationConfig = new CompactSerializationConfig();
compactSerializationConfig.setEnabled(true);
InternalSerializationService serializationService = new DefaultSerializationServiceBuilder().setSchemaService(schemaService).setConfig(new SerializationConfig().setCompactSerializationConfig(compactSerializationConfig)).build();
MainDTO expectedDTO = createMainDTO();
expectedDTO.nullableBool = null;
expectedDTO.p.localDateTimes[0] = null;
Data data = serializationService.toData(expectedDTO);
assertTrue(data.isCompact());
// internal generic record created on the servers on query
InternalGenericRecord internalGenericRecord = serializationService.readAsInternalGenericRecord(data);
String string = internalGenericRecord.toString();
Json.parse(string);
// generic record read from a remote instance without classes on the classpath
List<String> excludes = Collections.singletonList("example.serialization");
FilteringClassLoader classLoader = new FilteringClassLoader(excludes, null);
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(classLoader);
InternalSerializationService ss2 = new DefaultSerializationServiceBuilder().setSchemaService(schemaService).setClassLoader(classLoader).setConfig(new SerializationConfig().setCompactSerializationConfig(new CompactSerializationConfig())).build();
GenericRecord genericRecord = ss2.toObject(data);
Json.parse(genericRecord.toString());
// generic record build by API
GenericRecord apiGenericRecord = createCompactGenericRecord(expectedDTO);
Json.parse(apiGenericRecord.toString());
} finally {
Thread.currentThread().setContextClassLoader(contextClassLoader);
}
}
use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class CompactStreamSerializerTest method createSerializationService.
private InternalSerializationService createSerializationService() {
CompactSerializationConfig compactSerializationConfig = new CompactSerializationConfig();
compactSerializationConfig.setEnabled(true);
return new DefaultSerializationServiceBuilder().setSchemaService(schemaService).setConfig(new SerializationConfig().setCompactSerializationConfig(compactSerializationConfig)).build();
}
use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class CompactStreamSerializerTest method testSchemaEvolution_fieldAdded.
@Test
public void testSchemaEvolution_fieldAdded() {
SerializationConfig serializationConfig = new SerializationConfig();
// Using this registration to mimic schema evolution. This is usage is not advised.
serializationConfig.getCompactSerializationConfig().setEnabled(true).register(EmployeeDTO.class, EmployeeDTO.class.getName(), new CompactSerializer<EmployeeDTO>() {
@Nonnull
@Override
public EmployeeDTO read(@Nonnull CompactReader in) {
throw new UnsupportedOperationException("We will not read from here on this test");
}
@Override
public void write(@Nonnull CompactWriter out, @Nonnull EmployeeDTO object) {
out.writeInt32("age", object.getAge());
out.writeInt64("id", object.getId());
out.writeString("surname", "sir");
}
});
SerializationService serializationService = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).setSchemaService(schemaService).build();
EmployeeDTO expected = new EmployeeDTO(20, 102310312);
Data data = serializationService.toData(expected);
SerializationConfig serializationConfig2 = new SerializationConfig();
serializationConfig2.getCompactSerializationConfig().setEnabled(true);
SerializationService serializationService2 = new DefaultSerializationServiceBuilder().setSchemaService(schemaService).setConfig(serializationConfig2).build();
EmployeeDTO actual = serializationService2.toObject(data);
assertEquals(expected.getAge(), actual.getAge());
assertEquals(expected.getId(), actual.getId());
}
use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class CompactStreamSerializerTest method testWithExplicitSerializer.
@Test
public void testWithExplicitSerializer() {
SerializationConfig serializationConfig = new SerializationConfig();
serializationConfig.getCompactSerializationConfig().setEnabled(true).register(EmployeeDTO.class, "employee", new EmployeeDTOSerializer());
SerializationService serializationService = new DefaultSerializationServiceBuilder().setSchemaService(schemaService).setConfig(serializationConfig).build();
EmployeeDTO employeeDTO = new EmployeeDTO(30, 102310312);
Data data = serializationService.toData(employeeDTO);
Object object = serializationService.toObject(data);
EmployeeDTO actual = (EmployeeDTO) object;
assertEquals(employeeDTO, actual);
}
use of com.hazelcast.config.SerializationConfig in project hazelcast by hazelcast.
the class CompactWithSchemaStreamSerializerTest method createSerializationService.
private InternalSerializationService createSerializationService() {
SchemaService schemaService = CompactTestUtil.createInMemorySchemaService();
CompactSerializationConfig compactSerializationConfig = new CompactSerializationConfig();
compactSerializationConfig.setEnabled(true);
return new DefaultSerializationServiceBuilder().setSchemaService(schemaService).setConfig(new SerializationConfig().setCompactSerializationConfig(compactSerializationConfig)).build();
}
Aggregations