Java Code Examples for com.fasterxml.jackson.databind.node.BooleanNode#TRUE

The following examples show how to use com.fasterxml.jackson.databind.node.BooleanNode#TRUE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BuiltinFunctions.java    From jslt with Apache License 2.0 5 votes vote down vote up
public JsonNode call(JsonNode input, JsonNode[] arguments) {
  JsonNode value = arguments[0];
  if (value.isNull())
    return value;
  else if (!value.isArray())
    throw new JsltException("all() requires an array, not " + value);

  for (int ix = 0; ix < value.size(); ix++) {
    JsonNode node = value.get(ix);
    if (!NodeUtils.isTrue(node))
      return BooleanNode.FALSE;
  }
  return BooleanNode.TRUE;
}
 
Example 2
Source File: BuiltinFunctions.java    From jslt with Apache License 2.0 5 votes vote down vote up
public JsonNode call(JsonNode input, JsonNode[] arguments) {
  JsonNode value = arguments[0];
  if (value.isNull())
    return value;
  else if (!value.isArray())
    throw new JsltException("any() requires an array, not " + value);

  for (int ix = 0; ix < value.size(); ix++) {
    JsonNode node = value.get(ix);
    if (NodeUtils.isTrue(node))
      return BooleanNode.TRUE;
  }
  return BooleanNode.FALSE;
}
 
Example 3
Source File: BuiltinFunctions.java    From jslt with Apache License 2.0 5 votes vote down vote up
public JsonNode call(JsonNode input, JsonNode[] arguments) {
  if (arguments[1].isNull())
    return BooleanNode.FALSE; // nothing is contained in null

  else if (arguments[1].isArray()) {
    for (int ix = 0; ix < arguments[1].size(); ix++)
      if (arguments[1].get(ix).equals(arguments[0]))
        return BooleanNode.TRUE;

  } else if (arguments[1].isObject()) {
    String key = NodeUtils.toString(arguments[0], true);
    if (key == null)
      return BooleanNode.FALSE;

    return NodeUtils.toJson(arguments[1].has(key));

  } else if (arguments[1].isTextual()) {
    String sub = NodeUtils.toString(arguments[0], true);
    if (sub == null)
      return BooleanNode.FALSE;

    String str = arguments[1].asText();
    return NodeUtils.toJson(str.indexOf(sub) != -1);

  } else
    throw new JsltException("Contains cannot operate on " + arguments[1]);

  return BooleanNode.FALSE;
}
 
Example 4
Source File: OrOperator.java    From jslt with Apache License 2.0 5 votes vote down vote up
public JsonNode apply(Scope scope, JsonNode input) {
  boolean v1 = NodeUtils.isTrue(left.apply(scope, input));
  if (v1)
    return BooleanNode.TRUE;

  boolean v2 = NodeUtils.isTrue(right.apply(scope, input));
  return NodeUtils.toJson(v1 || v2);
}
 
Example 5
Source File: FunctionWrapper.java    From jslt with Apache License 2.0 5 votes vote down vote up
public JsonNode convert(Object node) {
  if (node == null)
    return NullNode.instance;
  else if ((Boolean) node)
    return BooleanNode.TRUE;
  else
    return BooleanNode.FALSE;
}
 
Example 6
Source File: JacksonScalars.java    From graphql-spqr with Apache License 2.0 5 votes vote down vote up
@Override
public BooleanNode parseValue(Object input) {
    if (input instanceof Boolean) {
        return (Boolean) input ? BooleanNode.TRUE : BooleanNode.FALSE;
    }
    if (input instanceof BooleanNode) {
        return (BooleanNode) input;
    }
    throw valueParsingException(input, Boolean.class, BooleanNode.class);
}
 
Example 7
Source File: BooleanJsonPropertyMapper.java    From rest-schemagen with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectNode toJson(JsonProperty jsonProperty) {
    Function<Object,JsonNode> nodeCreator = value -> ((Boolean) value) ? BooleanNode.TRUE
            : BooleanNode.FALSE;
    return primitiveJsonPropertyBuilder.forProperty(jsonProperty)
            .withType("boolean")
            .withDefaultValue(BooleanNode.FALSE)
            .withDefaultAndAllowedValues(nodeCreator).build();
}
 
Example 8
Source File: OptimizedStaticContainsFunction.java    From jslt with Apache License 2.0 4 votes vote down vote up
public JsonNode call(JsonNode input, JsonNode[] arguments) {
  if (values.contains(arguments[0]))
    return BooleanNode.TRUE;
  else
    return BooleanNode.FALSE;
}
 
Example 9
Source File: NodeUtils.java    From jslt with Apache License 2.0 4 votes vote down vote up
public static JsonNode toJson(boolean value) {
  if (value)
    return BooleanNode.TRUE;
  else
    return BooleanNode.FALSE;
}
 
Example 10
Source File: JacksonScalars.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@Override
public BooleanNode parseLiteral(Object input) {
    return literalOrException(input, BooleanValue.class).isValue() ? BooleanNode.TRUE : BooleanNode.FALSE;
}