com.base4j.mvc.util.JsonUtils Maven / Gradle / Ivy
The newest version!
package com.base4j.mvc.util;
import java.io.IOException;
import com.base4j.mvc.conf.JacksonCustomObjectMapper;
import com.fasterxml.jackson.core.JsonProcessingException;
public class JsonUtils {
private static JacksonCustomObjectMapper objectMapper = new JacksonCustomObjectMapper();
public static String toJSONString(Object object) {
try {
return objectMapper.writeValueAsString(object);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException(e);
}
}
public static T parseObject(String json, Class clazz) {
try {
return objectMapper.readValue(json, clazz);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
public static JacksonCustomObjectMapper getObjectMapper() {
return objectMapper;
}
}