/** * Creates a default {@link ObjectMapper} configuration instance, as used by the singleton * {@link Json} instance. * * @return A new {@link ObjectMapper} with the default configuration applied to it. */ public static ObjectMapper createDefaultMapper() { final ObjectMapper mapper = new ObjectMapper() .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .configure(DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS, true) .setSerializationInclusion(Include.NON_NULL); mapper .configOverride(Date.class) .setFormat(JsonFormat.Value.forPattern(Iso8601.DATE_TIME_MILLIS_FORMAT)); return mapper; }
private ObjectMapper defaultInit(ObjectMapper objectMapper) { objectMapper.configOverride(LocalDate.class).setFormat(JsonFormat.Value.forPattern(dateDeserializeContext.getDatePattern())); objectMapper.configOverride(LocalTime.class).setFormat(JsonFormat.Value.forPattern(dateDeserializeContext.getTimePattern())); objectMapper.configOverride(LocalDateTime.class).setFormat(JsonFormat.Value.forPattern(dateDeserializeContext.getDateTimePattern())); objectMapper.configOverride(java.time.LocalDate.class).setFormat(JsonFormat.Value.forPattern(dateDeserializeContext.getDatePattern())); objectMapper.configOverride(java.time.LocalTime.class).setFormat(JsonFormat.Value.forPattern(dateDeserializeContext.getTimePattern())); objectMapper.configOverride(java.time.LocalDateTime.class).setFormat(JsonFormat.Value.forPattern(dateDeserializeContext.getDateTimePattern())); objectMapper.setSerializationInclusion(NON_NULL) .disable(FAIL_ON_EMPTY_BEANS) .disable(FAIL_ON_UNKNOWN_PROPERTIES) .registerModules(new JodaModule(), new ParameterNamesModule(JsonCreator.Mode.PROPERTIES), new Jdk8Module(), new JavaTimeModule()); return objectMapper; } }