Search in sources :

Example 1 with DateTimeSerializer

use of com.fasterxml.jackson.datatype.joda.ser.DateTimeSerializer in project oap by oaplatform.

the class ParserPerformance method performance.

@Test
public void performance() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new Jdk8Module());
    final JodaModule module = new JodaModule();
    module.addDeserializer(DateTime.class, forType(DateTime.class));
    module.addSerializer(DateTime.class, new DateTimeSerializer(jodaDateFormat, 0));
    mapper.registerModule(module);
    mapper.enable(DeserializationFeature.USE_LONG_FOR_INTS);
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.registerModule(new OapJsonModule());
    benchmark("mapParser-jackson", 5000, () -> mapper.writeValueAsString(mapper.readValue(yearJson, Map.class))).run();
    final ObjectMapper mapper2 = new ObjectMapper();
    mapper2.registerModule(new Jdk8Module());
    mapper2.registerModule(module);
    mapper2.enable(DeserializationFeature.USE_LONG_FOR_INTS);
    mapper2.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    mapper2.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    mapper2.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
    mapper2.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper2.registerModule(new OapJsonModule());
    mapper2.registerModule(new AfterburnerModule());
    benchmark("mapParser-jackson2", 5000, () -> mapper2.writeValueAsString(mapper2.readValue(yearJson, Map.class))).run();
}
Also used : Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) AfterburnerModule(com.fasterxml.jackson.module.afterburner.AfterburnerModule) JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) DateTimeSerializer(com.fasterxml.jackson.datatype.joda.ser.DateTimeSerializer) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)1 JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)1 DateTimeSerializer (com.fasterxml.jackson.datatype.joda.ser.DateTimeSerializer)1 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)1 Map (java.util.Map)1 DateTime (org.joda.time.DateTime)1 Test (org.testng.annotations.Test)1