uk.gov.service.payments.commons.api.json.JsonMapper Maven / Gradle / Ivy
package uk.gov.service.payments.commons.api.json;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import static org.apache.commons.lang3.StringUtils.isEmpty;
public class JsonMapper {
private ObjectMapper objectMapper;
public JsonMapper(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}
public Map getAsMap(JsonNode jsonNode) {
if (jsonNode != null) {
if ((jsonNode.isTextual() && !isEmpty(jsonNode.asText())) || (!jsonNode.isNull() && jsonNode.isObject())) {
try {
return objectMapper.readValue(jsonNode.traverse(), new TypeReference