ie.curiositysoftware.utils.UnirestHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of testmodeller Show documentation
Show all versions of testmodeller Show documentation
Java client library for the Curiosity Software product TestModeller
package ie.curiositysoftware.utils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import kong.unirest.ObjectMapper;
import kong.unirest.Unirest;
import java.io.IOException;
public class UnirestHelper {
public static void initUnirestMapper()
{
ObjectMapper om = (new ObjectMapper() {
public com.fasterxml.jackson.databind.ObjectMapper jacksonObjectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
{
jacksonObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
public T readValue(String value, Class valueType) {
try {
return jacksonObjectMapper.readValue(value, valueType);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public String writeValue(Object value) {
try {
return jacksonObjectMapper.writeValueAsString(value);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
});
Unirest.config().setObjectMapper(om);
}
}