public class JsonHelper {
static ObjectMapper getMapper() {
ObjectMapper mapper;
mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
return mapper;
}
public static String encode(Object object) throws JsonProcessingException {
return getMapper().writeValueAsString(object);
}
public static <T> T decode(String json, Class<T> cls) throws IOException {
return getMapper().readValue(json, cls);
}
}
json - 使用jackson进行序列化/反序列化
最新推荐文章于 2022-03-09 17:31:01 发布