JacksonUtil Jdk8Module added along with jackson-datatype-jdk8 dependency to address the Optional mapping
This commit is contained in:
parent
ce24f2e765
commit
1f1086f106
@ -104,6 +104,10 @@
|
|||||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
|
<artifactId>jackson-datatype-jdk8</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@ -28,6 +28,7 @@ import com.fasterxml.jackson.databind.SerializationFeature;
|
|||||||
import com.fasterxml.jackson.databind.json.JsonMapper;
|
import com.fasterxml.jackson.databind.json.JsonMapper;
|
||||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
||||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -54,22 +55,30 @@ import java.util.regex.Pattern;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class JacksonUtil {
|
public class JacksonUtil {
|
||||||
|
|
||||||
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
public static final ObjectMapper OBJECT_MAPPER = JsonMapper.builder()
|
||||||
|
.addModule(new Jdk8Module())
|
||||||
|
.build();
|
||||||
public static final ObjectMapper PRETTY_SORTED_JSON_MAPPER = JsonMapper.builder()
|
public static final ObjectMapper PRETTY_SORTED_JSON_MAPPER = JsonMapper.builder()
|
||||||
|
.addModule(new Jdk8Module())
|
||||||
.enable(SerializationFeature.INDENT_OUTPUT)
|
.enable(SerializationFeature.INDENT_OUTPUT)
|
||||||
.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true)
|
.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true)
|
||||||
.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true)
|
.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true)
|
||||||
.build();
|
.build();
|
||||||
public static ObjectMapper ALLOW_UNQUOTED_FIELD_NAMES_MAPPER = JsonMapper.builder()
|
public static ObjectMapper ALLOW_UNQUOTED_FIELD_NAMES_MAPPER = JsonMapper.builder()
|
||||||
|
.addModule(new Jdk8Module())
|
||||||
.configure(JsonWriteFeature.QUOTE_FIELD_NAMES.mappedFeature(), false)
|
.configure(JsonWriteFeature.QUOTE_FIELD_NAMES.mappedFeature(), false)
|
||||||
.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
|
.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
|
||||||
.build();
|
.build();
|
||||||
public static final ObjectMapper IGNORE_UNKNOWN_PROPERTIES_JSON_MAPPER = JsonMapper.builder()
|
public static final ObjectMapper IGNORE_UNKNOWN_PROPERTIES_JSON_MAPPER = JsonMapper.builder()
|
||||||
|
.addModule(new Jdk8Module())
|
||||||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static ObjectMapper getObjectMapperWithJavaTimeModule() {
|
public static ObjectMapper getObjectMapperWithJavaTimeModule() {
|
||||||
return new ObjectMapper().registerModule(new JavaTimeModule());
|
return JsonMapper.builder()
|
||||||
|
.addModule(new Jdk8Module())
|
||||||
|
.addModule(new JavaTimeModule())
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T convertValue(Object fromValue, Class<T> toValueType) {
|
public static <T> T convertValue(Object fromValue, Class<T> toValueType) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user