ObjectMapperFactory.java

  1. /*
  2.  * This file is part of the pl.wrzasq.lambda.
  3.  *
  4.  * @license http://mit-license.org/ The MIT license
  5.  * @copyright 2018 - 2019 © by Rafał Wrzeszcz - Wrzasq.pl.
  6.  */

  7. package pl.wrzasq.lambda.json;

  8. import com.fasterxml.jackson.databind.DeserializationFeature;
  9. import com.fasterxml.jackson.databind.ObjectMapper;
  10. import com.fasterxml.jackson.databind.SerializationFeature;
  11. import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

  12. /**
  13.  * Default Jackson ObjectMapper provider.
  14.  */
  15. public class ObjectMapperFactory {
  16.     /**
  17.      * Creates Jackson mapper.
  18.      *
  19.      * @return Object mapper to be used around the system.
  20.      */
  21.     public static ObjectMapper createObjectMapper() {
  22.         var objectMapper = new ObjectMapper();
  23.         objectMapper.registerModule(new JavaTimeModule());
  24.         objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
  25.         objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  26.         objectMapper.configure(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE, false);
  27.         return objectMapper;
  28.     }
  29. }