use of example.serialization.MainDTO in project hazelcast by hazelcast.
the class CompactTestUtil method createMainDTO.
@Nonnull
static MainDTO createMainDTO() {
NamedDTO[] nn = new NamedDTO[2];
nn[0] = new NamedDTO("name", 123);
nn[1] = new NamedDTO("name", 123);
InnerDTO inner = new InnerDTO(new boolean[] { true, false }, new byte[] { 0, 1, 2 }, new short[] { 3, 4, 5 }, new int[] { 9, 8, 7, 6 }, new long[] { 0, 1, 5, 7, 9, 11 }, new float[] { 0.6543f, -3.56f, 45.67f }, new double[] { 456.456, 789.789, 321.321 }, nn, new BigDecimal[] { new BigDecimal("12345"), new BigDecimal("123456") }, new LocalTime[] { LocalTime.now(), LocalTime.now() }, new LocalDate[] { LocalDate.now(), LocalDate.now() }, new LocalDateTime[] { LocalDateTime.now() }, new OffsetDateTime[] { OffsetDateTime.now() }, new Boolean[] { true, false, null }, new Byte[] { 0, 1, 2, null }, new Short[] { 3, 4, 5, null }, new Integer[] { 9, 8, 7, 6, null }, new Long[] { 0L, 1L, 5L, 7L, 9L, 11L }, new Float[] { 0.6543f, -3.56f, 45.67f }, new Double[] { 456.456, 789.789, 321.321 }, new LocalTime[] { LocalTime.now(), LocalTime.now() }, new LocalDate[] { LocalDate.now(), LocalDate.now(), null }, new LocalDateTime[] { LocalDateTime.now(), null }, new OffsetDateTime[] { OffsetDateTime.now() });
return new MainDTO((byte) 113, true, (short) -500, 56789, -50992225L, 900.5678f, -897543.3678909d, "this is main object created for testing!", inner, new BigDecimal("12312313"), LocalTime.now(), LocalDate.now(), LocalDateTime.now(), OffsetDateTime.now(), (byte) 113, true, (short) -500, 56789, -50992225L, 900.5678f, -897543.3678909d);
}
use of example.serialization.MainDTO 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 example.serialization.MainDTO in project hazelcast by hazelcast.
the class CompactStreamSerializerTest method testGenericRecordHashcode_Equals.
@Test
public void testGenericRecordHashcode_Equals() {
SerializationService serializationService = createSerializationService();
MainDTO expectedDTO = createMainDTO();
GenericRecord expectedGenericRecord = createCompactGenericRecord(expectedDTO);
Data data = serializationService.toData(expectedGenericRecord);
Object object = serializationService.toObject(data);
GenericRecord genericRecord = (GenericRecord) object;
assertTrue(expectedGenericRecord.equals(genericRecord));
assertTrue(genericRecord.equals(expectedGenericRecord));
assertEquals(expectedGenericRecord.hashCode(), genericRecord.hashCode());
}
use of example.serialization.MainDTO in project hazelcast by hazelcast.
the class CompactStreamSerializerTest method testAllTypesWithReflectiveSerializer.
@Test
public void testAllTypesWithReflectiveSerializer() {
SerializationService serializationService = createSerializationService();
MainDTO expected = createMainDTO();
Data data = serializationService.toData(expected);
MainDTO actual = serializationService.toObject(data);
assertEquals(expected, actual);
}
Aggregations