|
11 | 11 | import com.fasterxml.jackson.core.JsonProcessingException; |
12 | 12 | import com.fasterxml.jackson.core.type.TypeReference; |
13 | 13 | import com.fasterxml.jackson.databind.*; |
| 14 | +import com.fasterxml.jackson.databind.json.JsonMapper; |
14 | 15 | import com.fasterxml.jackson.databind.module.SimpleModule; |
15 | 16 | import com.fasterxml.jackson.databind.node.ArrayNode; |
16 | 17 | import com.fasterxml.jackson.databind.node.ObjectNode; |
@@ -52,17 +53,19 @@ public static ObjectMapper createObjectMapper(final ModuleOptions options) { |
52 | 53 | final List<SimpleModule> moduleList = new ArrayList<>(); |
53 | 54 | suppliers.iterator().forEachRemaining(moduleSupplier -> moduleList.add(moduleSupplier.getModule(options))); |
54 | 55 |
|
55 | | - final ObjectMapper objectMapper = new ObjectMapper(); |
56 | | - objectMapper.registerModule(new JavaTimeModule()) //provides serialization and deserialization for LocalDate and LocalTime (JSR310 Jackson module) |
57 | | - .registerModule(new ZonedDateTimeSerializationModule()) //custom serializer for LocalDate, LocalTime and ZonedDateTime |
58 | | - .registerModule(new ZonedDateTimeDeserializationModule()) //custom deserializer for ZonedDateTime |
59 | | - .registerModule(new LocalDateDeserializationModule()) //custom deserializer for LocalDate |
60 | | - .registerModules(loader) |
61 | | - .registerModules(moduleList) |
62 | | - .setSerializationInclusion(JsonInclude.Include.NON_NULL) //ignore null fields |
| 56 | + return JsonMapper.builder() |
| 57 | + .configure(MapperFeature.REQUIRE_TYPE_ID_FOR_SUBTYPES, false) |
63 | 58 | .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) |
64 | | - .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); |
65 | | - return objectMapper; |
| 59 | + .configure(DeserializationFeature.FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY, false) |
| 60 | + .configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false) |
| 61 | + .serializationInclusion(JsonInclude.Include.NON_NULL) |
| 62 | + .addModule(new JavaTimeModule()) |
| 63 | + .addModule(new ZonedDateTimeSerializationModule()) //custom serializer for LocalDate, LocalTime and ZonedDateTime |
| 64 | + .addModule(new ZonedDateTimeDeserializationModule()) //custom deserializer for ZonedDateTime |
| 65 | + .addModule(new LocalDateDeserializationModule()) //custom deserializer for LocalDate |
| 66 | + .addModules(loader) |
| 67 | + .addModules(moduleList) |
| 68 | + .build(); |
66 | 69 | } |
67 | 70 |
|
68 | 71 | /** |
|
0 commit comments