use of com.fasterxml.jackson.databind.module.SimpleModule in project Gaffer by gchq.
the class RoaringBitmapJsonSerialisationTest method testCanSerialiseWithCustomObjectMapper.
@Test
public void testCanSerialiseWithCustomObjectMapper() throws IOException {
//Bitmap of (2,3000,300000) serialised in 0.5.11 Roaring Bitmap base 64 encoded
String serialisedComparisonBitmap = "{\"roaringBitmap\":{\"value\":\"OjAAAAIAAAAAAAEABAAAABgAAAAcAAAAAgC4C+CT\"}}";
RoaringBitmap comparisonBitmap = new RoaringBitmap();
comparisonBitmap.add(2);
comparisonBitmap.add(3000);
comparisonBitmap.add(300000);
final ObjectMapper mapper = JSONSerialiser.createDefaultMapper();
final SimpleModule bitmapModule = new SimpleModule(RoaringBitmapConstants.BITMAP_MODULE_NAME, new Version(1, 0, 9, null, null, null));
bitmapModule.addSerializer(RoaringBitmap.class, new RoaringBitmapJsonSerialiser());
bitmapModule.addDeserializer(RoaringBitmap.class, new RoaringBitmapJsonDeserialiser());
mapper.registerModule(bitmapModule);
RoaringBitmap testBitmap = mapper.readValue(serialisedComparisonBitmap, RoaringBitmap.class);
assertEquals(comparisonBitmap, testBitmap);
String serialisedBitmap = mapper.writeValueAsString(testBitmap);
assertEquals(serialisedBitmap, serialisedComparisonBitmap);
}
use of com.fasterxml.jackson.databind.module.SimpleModule in project kafka by apache.
the class VerifiableConsumer method addKafkaSerializerModule.
private void addKafkaSerializerModule() {
SimpleModule kafka = new SimpleModule();
kafka.addSerializer(TopicPartition.class, new JsonSerializer<TopicPartition>() {
@Override
public void serialize(TopicPartition tp, JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeStartObject();
gen.writeObjectField("topic", tp.topic());
gen.writeObjectField("partition", tp.partition());
gen.writeEndObject();
}
});
mapper.registerModule(kafka);
}
use of com.fasterxml.jackson.databind.module.SimpleModule in project jackson-module-afterburner by FasterXML.
the class TestStdSerializerOverrides method testStringSerOverideWithAfterburner.
public void testStringSerOverideWithAfterburner() throws Exception {
final FooBean input = new FooBean();
final String EXP = "{\"field\":\"Foo:value\"}";
String json = mapperWithModule().registerModule(new SimpleModule("module", Version.unknownVersion()).addSerializer(String.class, new MyStringSerializer())).writeValueAsString(input);
assertEquals(EXP, json);
}
use of com.fasterxml.jackson.databind.module.SimpleModule in project jackson-module-afterburner by FasterXML.
the class TestStdDeserializerOverrides method testStringDeserOverideWithAfterburner.
// for [module-afterburner#59]
public void testStringDeserOverideWithAfterburner() throws Exception {
final String json = "{\"field\": \"value & value\"}";
final String EXP = "value & value";
final Module module = new SimpleModule("module", Version.unknownVersion()) {
@Override
public void setupModule(SetupContext context) {
context.addDeserializers(new Deserializers.Base() {
@Override
public JsonDeserializer<?> findBeanDeserializer(JavaType type, DeserializationConfig config, BeanDescription beanDesc) throws JsonMappingException {
if (type.hasRawClass(String.class)) {
return new DeAmpDeserializer();
}
return null;
}
});
}
};
// but then fails with Afterburner
Issue59Bean resultAB = mapperWithModule().registerModule(module).readValue(json, Issue59Bean.class);
assertEquals(EXP, resultAB.field);
}
use of com.fasterxml.jackson.databind.module.SimpleModule in project jackson-module-afterburner by FasterXML.
the class CustomBeanPropertyWriterTest method testCustomPropertyWriter.
public void testCustomPropertyWriter() throws Exception {
ObjectMapper objectMapper = mapperWithModule();
SimpleModule simpleModule = new SimpleModule();
simpleModule.setSerializerModifier(new Only2BeanSerializerModifier());
objectMapper.registerModule(simpleModule);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
SampleObject sampleObject = new SampleObject(null, 2, 3);
String json = objectMapper.writeValueAsString(sampleObject);
assertEquals("{\"field2\":2}", json);
}
Aggregations