com.fasterxml.jackson.databind.JsonNode.isBoolean()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(203)

本文整理了Java中com.fasterxml.jackson.databind.JsonNode.isBoolean()方法的一些代码示例,展示了JsonNode.isBoolean()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.isBoolean()方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.JsonNode
类名称:JsonNode
方法名:isBoolean

JsonNode.isBoolean介绍

[英]Method that can be used to check if this node was created from JSON boolean value (literals "true" and "false").
[中]方法,该方法可用于检查此节点是否是从JSON布尔值(文本“true”和“false”)创建的。

代码示例

代码示例来源:origin: auth0/java-jwt

@Override
public Boolean asBoolean() {
  return !data.isBoolean() ? null : data.asBoolean();
}

代码示例来源:origin: Graylog2/graylog2-server

@Nullable
private Object valueNode(JsonNode jsonNode) {
  if (jsonNode.isInt()) {
    return jsonNode.asInt();
  } else if (jsonNode.isLong()) {
    return jsonNode.asLong();
  } else if (jsonNode.isIntegralNumber()) {
    return jsonNode.asLong();
  } else if (jsonNode.isFloatingPointNumber()) {
    return jsonNode.asDouble();
  } else if (jsonNode.isBoolean()) {
    return jsonNode.asBoolean();
  } else if (jsonNode.isNull()) {
    return null;
  } else {
    return jsonNode.asText();
  }
}

代码示例来源:origin: prestodb/presto

private Object toValue(JsonNode node)
      throws IOException
  {
    if (node.isTextual()) {
      return node.asText();
    }
    else if (node.isNumber()) {
      return node.numberValue();
    }
    else if (node.isBoolean()) {
      return node.asBoolean();
    }
    else if (node.isBinary()) {
      return node.binaryValue();
    }
    else {
      throw new IllegalStateException("Unexpected range bound value: " + node);
    }
  }
}

代码示例来源:origin: mrniko/netty-socketio

@Override
public AckArgs deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
    JsonProcessingException {
  List<Object> args = new ArrayList<Object>();
  AckArgs result = new AckArgs(args);
  ObjectMapper mapper = (ObjectMapper) jp.getCodec();
  JsonNode root = mapper.readTree(jp);
  AckCallback<?> callback = currentAckClass.get();
  Iterator<JsonNode> iter = root.iterator();
  int i = 0;
  while (iter.hasNext()) {
    Object val;
    Class<?> clazz = callback.getResultClass();
    if (callback instanceof MultiTypeAckCallback) {
      MultiTypeAckCallback multiTypeAckCallback = (MultiTypeAckCallback) callback;
      clazz = multiTypeAckCallback.getResultClasses()[i];
    }
    JsonNode arg = iter.next();
    if (arg.isTextual() || arg.isBoolean()) {
      clazz = Object.class;
    }
    val = mapper.treeToValue(arg, clazz);
    args.add(val);
    i++;
  }
  return result;
}

代码示例来源:origin: apache/pulsar

@Override
  public Object getField(String fieldName) {
    JsonNode fn = jn.get(fieldName);
    if (fn.isContainerNode()) {
      AtomicInteger idx = new AtomicInteger(0);
      List<Field> fields = Lists.newArrayList(fn.fieldNames())
        .stream()
        .map(f -> new Field(f, idx.getAndIncrement()))
        .collect(Collectors.toList());
      return new GenericJsonRecord(fields, fn);
    } else if (fn.isBoolean()) {
      return fn.asBoolean();
    } else if (fn.isInt()) {
      return fn.asInt();
    } else if (fn.isFloatingPointNumber()) {
      return fn.asDouble();
    } else if (fn.isDouble()) {
      return fn.asDouble();
    } else {
      return fn.asText();
    }
  }
}

代码示例来源:origin: docker-java/docker-java

@Override
  public VolumesRW deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
      throws IOException, JsonProcessingException {
    List<VolumeRW> volumesRW = new ArrayList<VolumeRW>();
    ObjectCodec oc = jsonParser.getCodec();
    JsonNode node = oc.readTree(jsonParser);
    for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) {
      Map.Entry<String, JsonNode> field = it.next();
      JsonNode value = field.getValue();
      if (!value.equals(NullNode.getInstance())) {
        if (!value.isBoolean()) {
          throw deserializationContext.mappingException("Expected access mode for '" + field.getKey()
              + "' in host but got '" + value + "'.");
        }
        VolumeRW bind = new VolumeRW(new Volume(field.getKey()), AccessMode.fromBoolean(value.asBoolean()));
        volumesRW.add(bind);
      }
    }
    return new VolumesRW(volumesRW.toArray(new VolumeRW[volumesRW.size()]));
  }
}

代码示例来源:origin: spullara/mustache.java

public static Object toObject(final JsonNode node) {
 if (node.isArray()) {
  return new ArrayList() {
   {
    for (JsonNode jsonNodes : node) {
     add(toObject(jsonNodes));
    }
   }
  };
 } else if (node.isObject()) {
  return new HashMap() {
   {
    for (Iterator<Map.Entry<String, JsonNode>> i = node.fields(); i.hasNext();) {
     Map.Entry<String, JsonNode> next = i.next();
     Object o = toObject(next.getValue());
     put(next.getKey(), o);
    }
   }
  };
 } else if (node.isBoolean()) {
  return node.booleanValue();
 } else if (node.isNull()) {
  return null;
 } else {
  return node.asText();
 }
}

代码示例来源:origin: spullara/mustache.java

private Object convert(final JsonNode value) {
  if (value == null || value.isNull()) return null;
  if (value.isBoolean()) {
   return value.booleanValue();
  } else if (value.isValueNode()) {
   return value.asText();
  } else if (value.isArray()) {
   return (Iterable) () -> new Iterator() {
    private Iterator<JsonNode> iterator = value.iterator();
    @Override
    public boolean hasNext() {
     return iterator.hasNext();
    }
    @Override
    public Object next() {
     return convert(iterator.next());
    }
    @Override
    public void remove() {
    }
   };
  } else {
   return new JsonMap(value);
  }
 }
}

代码示例来源:origin: knowm/XChange

boolean success = true;
final List<String> errors = new ArrayList<>();
if (successNode.isBoolean()) {
 success = successNode.asBoolean();
 final JsonNode errorsNode = node.path("errors");

代码示例来源:origin: Activiti/Activiti

JsonNode resultNode = ((JsonNode) base).get(property.toString());
if (resultNode != null && resultNode.isValueNode()) {
  if (resultNode.isBoolean()) {
    result = resultNode.asBoolean();
  } else if (resultNode.isLong()) {

代码示例来源:origin: apache/nifi

private byte[] extractJNodeValue(final JsonNode n){
  if (n.isBoolean()){
    //boolean
    return clientService.toBytes(n.asBoolean());
  }else if(n.isNumber()){
    if(n.isIntegralNumber()){
      //interpret as Long
      return clientService.toBytes(n.asLong());
    }else{
      //interpret as Double
      return clientService.toBytes(n.asDouble());
    }
  }else{
    //if all else fails, interpret as String
    return clientService.toBytes(n.asText());
  }
}

代码示例来源:origin: apache/avro

return defaultValue.isNumber();
case BOOLEAN:
 return defaultValue.isBoolean();
case NULL:
 return defaultValue.isNull();

代码示例来源:origin: apache/usergrid

return json.asInt();
else if ( json.isNumber() || json.isBoolean() ) {
  return BigInteger.valueOf( json.asLong() );

代码示例来源:origin: graphhopper/graphhopper

@Override
  public PathDetail deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    JsonNode pathDetail = jp.readValueAsTree();
    if (pathDetail.size() != 3)
      throw new JsonParseException(jp, "PathDetail array must have exactly 3 entries but was " + pathDetail.size());

    JsonNode from = pathDetail.get(0);
    JsonNode to = pathDetail.get(1);
    JsonNode val = pathDetail.get(2);

    PathDetail pd;
    if (val.isBoolean())
      pd = new PathDetail(val.asBoolean());
    else if (val.isLong())
      pd = new PathDetail(val.asLong());
    else if (val.isInt())
      pd = new PathDetail(val.asInt());
    else if (val.isDouble())
      pd = new PathDetail(val.asDouble());
    else if (val.isTextual())
      pd = new PathDetail(val.asText());
    else
      throw new JsonParseException(jp, "Unsupported type of PathDetail value " + pathDetail.getNodeType().name());

    pd.setFirst(from.asInt());
    pd.setLast(to.asInt());
    return pd;
  }
}

代码示例来源:origin: Graylog2/graylog2-server

if (valueType == ValueType.BOOLEAN && value.isBoolean()) {
  return ValueReference.of(value.booleanValue());
} else if (valueType == ValueType.DOUBLE && value.isDouble()) {

代码示例来源:origin: apache/avro

} else if (jsonNode.isNull()) {
 return JsonProperties.NULL_VALUE;
} else if (jsonNode.isBoolean()) {
 return jsonNode.asBoolean();
} else if (jsonNode.isInt()) {

代码示例来源:origin: apache/usergrid

else if ( json.isNumber() || json.isBoolean() ) {
  return BigInteger.valueOf( json.asLong() );

代码示例来源:origin: json-path/JsonPath

} else if (e.isBoolean()) {
  return e.asBoolean();
} else if (e.isInt()) {

代码示例来源:origin: apache/hive

return (new Text(value.textValue()));
case BOOLEAN:
 return (new BooleanWritable(value.isBoolean() ? value.booleanValue() : Boolean.valueOf(value.textValue())));
default:
 throw new SerDeException("Unknown type: " + typeInfo.getTypeName());

代码示例来源:origin: joelittlejohn/jsonschema2pojo

public JDefinedClass apply(String nodeName, JsonNode node, JsonNode parent, JDefinedClass jclass, Schema schema) {
  if (node != null && node.isBoolean() && node.asBoolean() == false) {

相关文章