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

The following examples show how to use com.fasterxml.jackson.databind.node.BooleanNode#FALSE . 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: SchemaGenerationContextImpl.java    From jsonschema-generator with Apache License 2.0 5 votes vote down vote up
/**
 * Preparation Step: create a node for a schema representing the given method's associated return type.
 *
 * @param method method to populate the schema node for
 * @param isNullable whether the method's return value may be null
 * @param forceInlineDefinition whether to generate an inline definition without registering it in this context
 * @param ignoredDefinitionProvider first custom definition provider to ignore
 * @return schema node representing the given method's return type
 */
private JsonNode createMethodSchema(MethodScope method, boolean isNullable, boolean forceInlineDefinition,
        CustomPropertyDefinitionProvider<MethodScope> ignoredDefinitionProvider) {
    if (method.isVoid()) {
        return BooleanNode.FALSE;
    }
    ObjectNode subSchema = this.generatorConfig.createObjectNode();
    ObjectNode methodAttributes = AttributeCollector.collectMethodAttributes(method, this);
    this.populateMemberSchema(method, subSchema, isNullable, forceInlineDefinition, methodAttributes, ignoredDefinitionProvider);
    return subSchema;
}
 
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) {
  // if data is missing then it doesn't match, end of story
  if (arguments[0].isNull())
    return BooleanNode.FALSE;

  String string = NodeUtils.toString(arguments[0], false);
  String regexp = NodeUtils.toString(arguments[1], true);
  if (regexp == null)
    throw new JsltException("test() can't test null regexp");

  Pattern p = getRegexp(regexp);
  java.util.regex.Matcher m = p.matcher(string);
  return NodeUtils.toJson(m.find(0));
}
 
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) {
  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 4
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 5
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 6
Source File: AndOperator.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.FALSE;

  boolean v2 = NodeUtils.isTrue(right.apply(scope, input));
  return NodeUtils.toJson(v1 && v2);
}
 
Example 7
Source File: NodeUtils.java    From jslt with Apache License 2.0 5 votes vote down vote up
public static boolean isTrue(JsonNode value) {
  return value != BooleanNode.FALSE &&
    !(value.isObject() && value.size() == 0) &&
    !(value.isTextual() && value.asText().length() == 0) &&
    !(value.isArray() && value.size() == 0) &&
    !(value.isNumber() && value.doubleValue() == 0.0) &&
    !value.isNull();
}
 
Example 8
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 9
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 10
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 11
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 12
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 13
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;
}