Search in sources :

Example 16 with JodaModule

use of com.fasterxml.jackson.datatype.joda.JodaModule in project mica2 by obiba.

the class TestUtil method convertObjectToJsonBytes.

/**
 * Convert an object to JSON byte array.
 *
 * @param object the object to convert
 * @return the JSON byte array
 * @throws IOException
 */
public static byte[] convertObjectToJsonBytes(Object object) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.registerModule(new JodaModule());
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    return mapper.writeValueAsBytes(object);
}
Also used : JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 17 with JodaModule

use of com.fasterxml.jackson.datatype.joda.JodaModule 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)

Example 18 with JodaModule

use of com.fasterxml.jackson.datatype.joda.JodaModule in project cloudconductor-agent-redhat by cinovo.

the class MapperFactory method createDefault.

public static ObjectMapper createDefault() {
    ObjectMapper m = new ObjectMapper();
    m.registerModule(new JodaModule());
    m.registerModule(new GuavaModule());
    m.setSerializationInclusion(Include.NON_NULL);
    m.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    m.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    m.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
    m.enable(MapperFeature.AUTO_DETECT_GETTERS);
    return m;
}
Also used : JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule)

Example 19 with JodaModule

use of com.fasterxml.jackson.datatype.joda.JodaModule in project kylo by Teradata.

the class ObjectMapperSerializer method getMapper.

/**
 * Return a reference to the Jackson2 ObjectMapper
 *
 * @return the ObjectMapper used to serialize/deserialize
 */
private static ObjectMapper getMapper() {
    if (mapper == null) {
        mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.registerModule(new JodaModule());
    }
    return mapper;
}
Also used : JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 20 with JodaModule

use of com.fasterxml.jackson.datatype.joda.JodaModule in project pictureapp by EyeSeeTea.

the class SurveyChecker method getEvents.

public static List<EventExtended> getEvents(JsonNode jsonNode) {
    TypeReference<List<Event>> typeRef = new TypeReference<List<Event>>() {
    };
    List<Event> events;
    try {
        if (jsonNode.has("events")) {
            ObjectMapper objectMapper = new ObjectMapper().registerModule(new JodaModule());
            events = objectMapper.readValue(jsonNode.get("events").traverse(), typeRef);
        } else {
            events = new ArrayList<>();
        }
    } catch (IOException e) {
        events = new ArrayList<>();
        e.printStackTrace();
    }
    List<EventExtended> eventExtendedList = new ArrayList<>();
    for (Event event : events) {
        EventFlow eventFlow = EventFlow.MAPPER.mapToDatabaseEntity(event);
        EventExtended eventExtended = new EventExtended(eventFlow);
        if (event.getDataValues() != null && event.getDataValues().size() > 0) {
            List<TrackedEntityDataValueFlow> trackedEntityDataValueFlows = TrackedEntityDataValueFlow.MAPPER.mapToDatabaseEntities(event.getDataValues());
            eventExtended.setDataValuesInMemory(trackedEntityDataValueFlows);
        }
        eventExtendedList.add(eventExtended);
    }
    return eventExtendedList;
}
Also used : EventExtended(org.eyeseetea.malariacare.data.sync.importer.models.EventExtended) EventFlow(org.hisp.dhis.client.sdk.android.api.persistence.flow.EventFlow) JodaModule(com.fasterxml.jackson.datatype.joda.JodaModule) TrackedEntityDataValueFlow(org.hisp.dhis.client.sdk.android.api.persistence.flow.TrackedEntityDataValueFlow) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Event(org.hisp.dhis.client.sdk.models.event.Event) ArrayList(java.util.ArrayList) List(java.util.List) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JodaModule (com.fasterxml.jackson.datatype.joda.JodaModule)45 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)37 Test (org.junit.Test)15 IOException (java.io.IOException)14 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)7 ClassPathResource (org.springframework.core.io.ClassPathResource)6 Resource (org.springframework.core.io.Resource)6 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)5 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)5 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)5 SimpleDateFormat (java.text.SimpleDateFormat)4 Bean (org.springframework.context.annotation.Bean)4 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)3 ArrayList (java.util.ArrayList)3 Before (org.junit.Before)3 Primary (org.springframework.context.annotation.Primary)3 MetricsModule (com.codahale.metrics.json.MetricsModule)2 PropertyNamingStrategy (com.fasterxml.jackson.databind.PropertyNamingStrategy)2 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)2 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)2