com.github.dikhan.pagerduty.client.events.JacksonObjectMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pagerduty-client Show documentation
Show all versions of pagerduty-client Show documentation
Simple Java PagerDuty client with full integration with PagerDuty Events APIs
package com.github.dikhan.pagerduty.client.events;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.github.dikhan.utils.JSONObjectSerializer;
import org.json.JSONObject;
import java.io.IOException;
public class JacksonObjectMapper implements com.mashape.unirest.http.ObjectMapper {
private static final ObjectMapper jacksonObjectMapper = makeObjectMapper();
private static ObjectMapper makeObjectMapper() {
com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(JSONObject.class, new JSONObjectSerializer());
mapper.registerModule(module);
return mapper;
}
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);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy