Skip to content

Commit

Permalink
feature: update JacksonUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
wangqi committed Mar 1, 2024
1 parent 18d3d86 commit 86a1f11
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -16,7 +17,10 @@
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
* jackson utility class.
Expand All @@ -28,9 +32,10 @@ public class JacksonUtil {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

static {
OBJECT_MAPPER.registerModule(new JavaTimeModule());
OBJECT_MAPPER.registerModule(new Jdk8Module());
OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
OBJECT_MAPPER.registerModule(new JavaTimeModule())
.registerModule(new Jdk8Module())
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
}

private JacksonUtil() {
Expand Down Expand Up @@ -136,7 +141,8 @@ public static <T> T toObject(JsonNode jsonNode, TypeReference<T> typeReference)
}

public static Map<String, Object> toMap(JsonNode jsonNode) {
return toObject(jsonNode, new TypeReference<Map<String, Object>>() {});
return toObject(jsonNode, new TypeReference<Map<String, Object>>() {
});
}

public static boolean checkJsonValid(String json) {
Expand Down

0 comments on commit 86a1f11

Please sign in to comment.