All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.enonic.xp.json.ObjectMapperHelper Maven / Gradle / Ivy

There is a newer version: 7.14.4
Show newest version
package com.enonic.xp.json;

import java.text.SimpleDateFormat;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

public final class ObjectMapperHelper
{
    public static ObjectMapper create()
    {
        final JsonMapper.Builder mapper = JsonMapper.builder();
        mapper.defaultDateFormat( new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ) );
        mapper.disable( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS );
        mapper.disable( SerializationFeature.FAIL_ON_EMPTY_BEANS );
        mapper.enable( MapperFeature.SORT_PROPERTIES_ALPHABETICALLY );
        mapper.serializationInclusion( JsonInclude.Include.ALWAYS );
        mapper.addModule( new JavaTimeModule() );
        return mapper.build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy