com.volcengine.ark.runtime.utils.JacksonUtil Maven / Gradle / Ivy
package com.volcengine.ark.runtime.utils;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
public class JacksonUtil {
private static final ObjectMapper objectMapper = defaultObjectMapper();
private static ObjectMapper defaultObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
return mapper;
}
public static JsonNode clsToJsonNode(Object o) {
return objectMapper.valueToTree(o);
}
public static T jsonNodeToCls(JsonNode j, Class cls) {
return objectMapper.convertValue(j, cls);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy