use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project Gaffer by gchq.
the class HyperLogLogPlusJsonDeserialiser method deserialize.
@Override
public HyperLogLogPlus deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
TreeNode treeNode = jsonParser.getCodec().readTree(jsonParser);
final TreeNode nestedHllp = treeNode.get("hyperLogLogPlus");
if (nonNull(nestedHllp)) {
treeNode = nestedHllp;
}
final HyperLogLogPlus hllp;
final TextNode jsonNodes = (TextNode) treeNode.get(HyperLogLogPlusJsonConstants.HYPER_LOG_LOG_PLUS_SKETCH_BYTES_FIELD);
if (isNull(jsonNodes)) {
final IntNode pNode = (IntNode) treeNode.get("p");
final IntNode spNode = (IntNode) treeNode.get("sp");
final int p = nonNull(pNode) ? pNode.asInt(DEFAULT_P) : DEFAULT_P;
final int sp = nonNull(spNode) ? spNode.asInt(DEFAULT_SP) : DEFAULT_SP;
hllp = new HyperLogLogPlus(p, sp);
} else {
hllp = HyperLogLogPlus.Builder.build(jsonNodes.binaryValue());
}
final ArrayNode offers = (ArrayNode) treeNode.get("offers");
if (nonNull(offers)) {
for (final JsonNode offer : offers) {
if (nonNull(offer)) {
hllp.offer(offer.asText());
}
}
}
return hllp;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project batfish by batfish.
the class JsonPathResult method extractValuesFromSuffix.
private void extractValuesFromSuffix(String displayVar, Extraction extraction, JsonPathExtractionHint jpeHint) {
for (Entry<String, JsonPathResultEntry> entry : _result.entrySet()) {
if (!_displayValues.containsKey(entry.getKey())) {
_displayValues.put(entry.getKey(), new HashMap<>());
}
if (entry.getValue().getSuffix() == null) {
throw new BatfishException("Cannot compute suffix-based display values with null suffix. " + "(Was suffix set to True in the original JsonPath Query?)");
}
Configuration.setDefaults(BatfishJsonPathDefaults.INSTANCE);
Configuration c = (new ConfigurationBuilder()).build();
Object jsonObject = JsonPath.parse(entry.getValue().getSuffix(), c).json();
JsonPathQuery query = new JsonPathQuery(jpeHint.getFilter(), true);
List<JsonNode> extractedList = new LinkedList<>();
switch(jpeHint.getUse()) {
case FUNCOFSUFFIX:
{
if (!extraction.getSchemaAsObject().isIntOrIntList()) {
throw new BatfishException("schema must be INT(LIST) with funcofsuffix-based extraction hint");
}
Object result = JsonPathAnswerer.computePathFunction(jsonObject, query);
if (result != null) {
if (result instanceof Integer) {
extractedList.add(new IntNode((Integer) result));
} else if (result instanceof ArrayNode) {
for (JsonNode node : (ArrayNode) result) {
if (!(node instanceof IntNode)) {
throw new BatfishException("Got non-integer result from path function after filter " + query.getPath());
}
extractedList.add(node);
}
} else {
throw new BatfishException("Unknown result type from computePathFunction");
}
}
}
break;
case PREFIXOFSUFFIX:
case SUFFIXOFSUFFIX:
{
JsonPathResult filterResult = JsonPathAnswerer.computeResult(jsonObject, query);
Map<String, JsonPathResultEntry> filterResultEntries = filterResult.getResult();
for (Entry<String, JsonPathResultEntry> resultEntry : filterResultEntries.entrySet()) {
JsonNode value = (jpeHint.getUse() == UseType.PREFIXOFSUFFIX) ? new TextNode(resultEntry.getValue().getPrefixPart(jpeHint.getIndex())) : resultEntry.getValue().getSuffix();
confirmValueType(value, extraction.getSchemaAsObject().getBaseType());
extractedList.add(value);
}
}
break;
default:
throw new BatfishException("Unknown UseType " + jpeHint.getUse());
}
if (extractedList.size() == 0) {
throw new BatfishException("Got no results after filtering suffix values of the answer" + "\nFilter: " + jpeHint.getFilter() + "\nJson: " + jsonObject);
}
if (extraction.getSchemaAsObject().isList()) {
ArrayNode arrayNode = BatfishObjectMapper.mapper().valueToTree(extractedList);
_displayValues.get(entry.getKey()).put(displayVar, arrayNode);
} else {
if (extractedList.size() > 1) {
throw new BatfishException("Got multiple results after filtering suffix values " + " of the answer, but the display type is non-list");
}
_displayValues.get(entry.getKey()).put(displayVar, extractedList.get(0));
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project snow-owl by b2ihealthcare.
the class TypedPropertyDeserializer method deserialize.
@Override
public TypedProperty deserialize(JsonParser parser, DeserializationContext ctx) throws IOException, JsonProcessingException {
String type = null;
String currentName = parser.currentName();
if (currentName.startsWith(VALUE_PREFIX)) {
type = currentName.replace(VALUE_PREFIX, "");
}
if (type == null) {
throw new IllegalArgumentException("Invalid parameter type with null value.");
}
TextNode node = (TextNode) parser.readValueAsTree();
String value = node.asText();
switch(type) {
case "String":
return new StringProperty(value);
case "Date":
return new DateProperty(FhirDates.parseDate(value));
case "DateTime":
return new DateTimeProperty(FhirDates.parseDate(value));
case "Instant":
return new InstantProperty(Instant.builder().instant(FhirDates.parseDate(value)).build());
default:
throw new IllegalArgumentException("Unsupported property type '" + type + "'.");
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project drools by kiegroup.
the class AbstractExpressionEvaluatorTest method isNodeEmpty.
@Test
public void isNodeEmpty() {
ObjectNode objectNode = new ObjectNode(factory);
assertTrue(expressionEvaluatorLocal.isNodeEmpty(objectNode));
objectNode.set("empty array", new ArrayNode(factory));
assertTrue(expressionEvaluatorLocal.isNodeEmpty(objectNode));
objectNode.set("key", new TextNode(VALUE));
assertFalse(expressionEvaluatorLocal.isNodeEmpty(objectNode));
ArrayNode arrayNode = new ArrayNode(factory);
assertTrue(expressionEvaluatorLocal.isNodeEmpty(arrayNode));
arrayNode.add(new TextNode(VALUE));
assertFalse(expressionEvaluatorLocal.isNodeEmpty(arrayNode));
assertTrue(expressionEvaluatorLocal.isNodeEmpty(new TextNode("")));
assertTrue(expressionEvaluatorLocal.isNodeEmpty(new TextNode(null)));
assertFalse(expressionEvaluatorLocal.isNodeEmpty(new TextNode(VALUE)));
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.TextNode in project drools by kiegroup.
the class AbstractExpressionEvaluatorTest method isListEmpty.
@Test
public void isListEmpty() {
ArrayNode json = new ArrayNode(factory);
assertTrue(expressionEvaluatorLocal.isListEmpty(json));
ObjectNode nestedNode = new ObjectNode(factory);
json.add(nestedNode);
assertTrue(expressionEvaluatorLocal.isListEmpty(json));
nestedNode.set("emptyField", new TextNode(""));
assertTrue(expressionEvaluatorLocal.isListEmpty(json));
nestedNode.set("notEmptyField", new TextNode("text"));
assertFalse(expressionEvaluatorLocal.isListEmpty(json));
}
Aggregations