use of com.hazelcast.internal.serialization.impl.InternalGenericRecord in project hazelcast by hazelcast.
the class PortableUpsertTargetTest method when_doesNotInjectIntoObject_then_insertsNull.
@Test
@Parameters(method = "objectClassDefinitions")
@SuppressWarnings("unused")
public void when_doesNotInjectIntoObject_then_insertsNull(ClassDefinition classDefinition, Object value, Function<InternalGenericRecord, Object> valueExtractor) throws IOException {
UpsertTarget target = new PortableUpsertTarget(classDefinition);
target.init();
Object portable = target.conclude();
InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
InternalGenericRecord record = ss.readAsInternalGenericRecord(ss.toData(portable));
assertThat(valueExtractor.apply(record)).isNull();
}
use of com.hazelcast.internal.serialization.impl.InternalGenericRecord in project hazelcast by hazelcast.
the class ExtractorGetter method getValue.
@Override
@SuppressWarnings("unchecked")
Object getValue(Object target) throws Exception {
Object extractionTarget = target;
// This part will be improved in 3.7 to avoid extra allocation
DefaultValueCollector collector = new DefaultValueCollector();
if (target instanceof Data) {
InternalGenericRecord record = serializationService.readAsInternalGenericRecord((Data) target);
extractionTarget = new GenericRecordQueryReader(record);
}
extractor.extract(extractionTarget, arguments, collector);
return collector.getResult();
}
use of com.hazelcast.internal.serialization.impl.InternalGenericRecord 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);
}
}
Aggregations