Posts Java jackson ObjectMapper configuration
Post
Cancel

Java jackson ObjectMapper configuration

  • Imports
1
2
3
4
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
  • Configuration to ignore unknown keys in json
1
2
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  • Configuration to prevent date from being written as timestamps
1
2
3
ObjectMapper objectMapper = new ObjectMapper();

objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
  • Configuration to set missing values as null in response
1
2
3
ObjectMapper objectMapper = new ObjectMapper();

objectMapper.setSerializationInclusion(Include.ALWAYS);
This post is licensed under CC BY 4.0 by the author.