![JAR search and dependency download from the Maven repository](/logo.png)
com.kcthota.JSONQuery.expressions.PrependToValueExpression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JSONQuery Show documentation
Show all versions of JSONQuery Show documentation
Helps querying Jackson JSONNode objects with varieties of expressions
/**
*
*/
package com.kcthota.JSONQuery.expressions;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.TextNode;
import com.kcthota.JSONQuery.exceptions.UnsupportedExprException;
/**
* Prepends the passed text to the value in the json node and returns a new TextNode
* @author Krishna Chaitanya Thota
* Apr 25, 2015 8:18:49 PM
*/
public class PrependToValueExpression extends ValueExpression {
private String prependText = "";
public PrependToValueExpression(String property, String prependText) {
super(property);
if(prependText!=null) {
this.prependText = prependText;
}
}
public PrependToValueExpression(String property, String prependText, ValueExpression innerExpression) {
super(property, innerExpression);
if(prependText!=null) {
this.prependText = prependText;
}
}
public JsonNode evaluate(JsonNode node) {
JsonNode valueNode = super.evaluate(node);
if(valueNode==null || !valueNode.isTextual()) {
throw new UnsupportedExprException("Property value is not a string");
}
return TextNode.valueOf(prependText + valueNode.textValue());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy