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

blocks.service.JsonUtil Maven / Gradle / Ivy

There is a newer version: 0.15
Show newest version
package blocks.service;

import akka.http.javadsl.marshallers.jackson.Jackson;
import akka.http.javadsl.marshalling.Marshaller;
import akka.http.javadsl.model.HttpEntity;
import akka.http.javadsl.model.RequestEntity;
import akka.http.javadsl.unmarshalling.Unmarshaller;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

public class JsonUtil {
    public static final ObjectMapper DEFAULT_OBJECT_MAPPER = getObjectMapper();

    private static ObjectMapper getObjectMapper() {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.registerModule(new Jdk8Module());
        objectMapper.registerModule(new JavaTimeModule());
        objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
        objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
        return objectMapper;
    }

    public static  Marshaller marshaller() {
        return Jackson.marshaller(DEFAULT_OBJECT_MAPPER);
    }

    public static  Unmarshaller unmarshaller(Class classParam) {
        return Jackson.unmarshaller(DEFAULT_OBJECT_MAPPER, classParam);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy