use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.
the class DefaultPortableReaderQuickTest method reader.
//
// Utilities
//
public GenericRecordQueryReader reader(Portable portable) throws IOException {
SerializationConfig serializationConfig = new SerializationConfig();
serializationConfig.addPortableFactory(TestPortableFactory.ID, new TestPortableFactory());
InternalSerializationService ss = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
ss.toData(NON_EMPTY_PORSCHE);
return new GenericRecordQueryReader(ss.readAsInternalGenericRecord(ss.toData(portable)));
}
use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.
the class PortableTest method test_1096_ByteArrayContentSame.
// https://github.com/hazelcast/hazelcast/issues/1096
@Test
public void test_1096_ByteArrayContentSame() {
SerializationService ss = new DefaultSerializationServiceBuilder().addPortableFactory(PORTABLE_FACTORY_ID, new TestPortableFactory()).build();
assertRepeatedSerialisationGivesSameByteArrays(ss, new NamedPortable("issue-1096", 1096));
assertRepeatedSerialisationGivesSameByteArrays(ss, new InnerPortable(new byte[] { 0, 1, 2 }, new char[] { 'c', 'h', 'a', 'r' }, 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 }, new NamedPortable[] { new NamedPortable("issue-1096", 1096) }, 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() }));
assertRepeatedSerialisationGivesSameByteArrays(ss, new RawDataPortable(1096L, "issue-1096".toCharArray(), new NamedPortable("issue-1096", 1096), 1096, "issue-1096", new ByteArrayDataSerializable(new byte[1])));
}
use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.
the class PortableTest method testGenericPortable_whenMultipleTypesAreUsed.
@Test(expected = HazelcastSerializationException.class)
public void testGenericPortable_whenMultipleTypesAreUsed() {
SerializationService ss = new DefaultSerializationServiceBuilder().addPortableFactory(1, new PortableFactory() {
@Override
public Portable create(int classId) {
switch(classId) {
case ParentGenericPortable.CLASS_ID:
return new ParentGenericPortable();
case ChildGenericPortable1.CLASS_ID:
return new ChildGenericPortable1();
case ChildGenericPortable2.CLASS_ID:
return new ChildGenericPortable2();
default:
throw new IllegalArgumentException();
}
}
}).build();
ss.toData(new ParentGenericPortable<ChildGenericPortable1>(new ChildGenericPortable1("aaa", "bbb")));
Data data = ss.toData(new ParentGenericPortable<ChildGenericPortable2>(new ChildGenericPortable2("ccc")));
ss.toObject(data);
}
use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.
the class PortableTest method testWriteRead_withNullPortableArray.
@Test
public void testWriteRead_withNullPortableArray() {
int portableVersion = 1;
ClassDefinitionBuilder builder0 = new ClassDefinitionBuilder(PORTABLE_FACTORY_ID, 1, portableVersion);
ClassDefinitionBuilder builder1 = new ClassDefinitionBuilder(PORTABLE_FACTORY_ID, 2, portableVersion);
builder0.addPortableArrayField("list", builder1.build());
SerializationService ss = new DefaultSerializationServiceBuilder().setPortableVersion(portableVersion).addClassDefinition(builder0.build()).addClassDefinition(builder1.build()).build();
Data data = ss.toData(new TestObject1());
SerializationService ss2 = new DefaultSerializationServiceBuilder().addPortableFactory(1, new PortableFactory() {
@Override
public Portable create(int classId) {
switch(classId) {
case 1:
return new TestObject1();
case 2:
return new TestObject2();
default:
return null;
}
}
}).build();
Object object = ss2.toObject(data);
assertNotNull(object);
assertTrue(object instanceof TestObject1);
}
use of com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder in project hazelcast by hazelcast.
the class PortableTest method testWriteObjectWithCustomSerializable.
@Test
public void testWriteObjectWithCustomSerializable() {
SerializationConfig config = new SerializationConfig();
SerializerConfig sc = new SerializerConfig().setImplementation(new CustomSerializationTest.FooXmlSerializer()).setTypeClass(CustomSerializationTest.Foo.class);
config.addSerializerConfig(sc);
SerializationService serializationService = new DefaultSerializationServiceBuilder().setPortableVersion(1).addPortableFactory(PORTABLE_FACTORY_ID, new TestPortableFactory()).setConfig(config).build();
CustomSerializationTest.Foo foo = new CustomSerializationTest.Foo("f");
ObjectCarryingPortable objectCarryingPortable1 = new ObjectCarryingPortable(foo);
Data data = serializationService.toData(objectCarryingPortable1);
ObjectCarryingPortable objectCarryingPortable2 = serializationService.toObject(data);
assertEquals(objectCarryingPortable1, objectCarryingPortable2);
}
Aggregations