com.sentenial.rest.client.utils.JsonUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nuapay-rest-client Show documentation
Show all versions of nuapay-rest-client Show documentation
NuaPay REST API Java Bindings
package com.sentenial.rest.client.utils;
import java.text.SimpleDateFormat;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonGenerator.Feature;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JsonUtils {
public static final ObjectMapper objectMapper = new ObjectMapper()
.setSerializationInclusion(Include.NON_NULL)
.enable(Feature.WRITE_BIGDECIMAL_AS_PLAIN)
.setDateFormat(new SimpleDateFormat("yyyy-MM-dd"));
public static T fromJson(String json, Class clazz) {
try {
return objectMapper.readValue(json, clazz);
} catch (Exception e) {
throw new JsonTransformationException(e);
}
}
public static String toJson(Object src) {
try {
return objectMapper.writeValueAsString(src);
} catch (Exception e) {
throw new JsonTransformationException(e);
}
}
}