com.mokung.pomegranate.jackson.handler.getter.StringGetter Maven / Gradle / Ivy
package com.mokung.pomegranate.jackson.handler.getter;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.NullNode;
import com.fasterxml.jackson.databind.node.TextNode;
import com.mokung.pomegranate.jackson.handler.Getter;
/**
*
* @author mokung
*/
public class StringGetter implements Getter {
@Override
public String getter(JsonNode valueNode, ObjectMapper mapper, boolean cast) {
if (valueNode instanceof TextNode) {
return valueNode.asText();
}
if (!cast || valueNode == null || valueNode instanceof NullNode) {
return null;
}
return valueNode.asText();
}
}