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

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

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

JsonNode.hasNonNull介绍

[英]Method that is similar to #has(int), but that will return false for explicitly added nulls.

This method is equivalent to:

node.get(index) != null && !node.get(index).isNull()

[中]

代码示例

代码示例来源:origin: HubSpot/Singularity

private JsonNode loadYamlField(String filename, String field) {
 final File yamlFile = new File(filename);
 if (!yamlFile.exists()) {
  return objectMapper.createObjectNode();
 }
 try {
  final JsonNode baseTree = objectMapper.readTree(yamlFile);
  return baseTree.hasNonNull(field) ? baseTree.get(field) : objectMapper.createObjectNode();
 } catch (Exception e) {
  throw Throwables.propagate(e);
 }
}

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

dsb.setTrain(loadDataSource(json.get("train"), base, nbase + ".train"));
dsb.setTest(loadDataSource(json.get("test"), base, nbase + ".test"));
if (json.hasNonNull("runtime")) {
  dsb.setRuntime(loadDataSource(json.get("runtime"), base, nbase + ".runtime"));

代码示例来源:origin: Texera/texera

public static String getUserDescription(JsonNode object) {
  if (object.hasNonNull(twitterConstant.USER)) {
    JsonNode user = object.get(twitterConstant.USER);
    if (user.hasNonNull(twitterConstant.DESCRIPTION)) {
      return user.get(twitterConstant.DESCRIPTION).asText();
    }
  }
  return informationNotAvailable;
}

代码示例来源:origin: GluuFederation/oxAuth

public void verifyThatMetadataIsValid(JsonNode metadata) {
    long count = Arrays.asList(metadata.hasNonNull("aaguid"), metadata.hasNonNull("assertionScheme"), metadata.hasNonNull("attestationTypes"),
        metadata.hasNonNull("description")).parallelStream().filter(f -> f == false).count();
    if (count != 0) {
      throw new Fido2RPRuntimeException("Invalid parameters in metadata");
    }
  }
}

代码示例来源:origin: Texera/texera

public static String getLanguage(JsonNode object) {
  if (object.hasNonNull(twitterConstant.LANGUAGE)) {
    return object.get(twitterConstant.LANGUAGE).asText();
  }
  return informationNotAvailable;
}

代码示例来源:origin: Texera/texera

public static String getText(JsonNode object) {
  if (object.hasNonNull(twitterConstant.TEXT)) {
    return object.get(twitterConstant.TEXT).asText();
  }
  return informationNotAvailable;
}

代码示例来源:origin: com.neotys.neoload/neoload-project

private void checkMandatoryFieldsForServer(final JsonNode jsonNode) throws IOException {
  for (String field : newArrayList(NAME, HOST)) {
    if (!jsonNode.hasNonNull(field)) {
      throw new IOException("'" + field + "'" + " field is mandatory for Server");
    }
  }
}

代码示例来源:origin: io.syndesis/connector-catalog

private String extractJsonTextString(JsonNode descriptor, String key) {
  if (descriptor != null && descriptor.hasNonNull(key)) {
    // TODO: If this is a real JSON object, print it as JSON
    // I.e. when JsonSchemaHelper is 'fixed', and
    // ExtractConnectorDescriptorsMojo updated to store real json objects for
    // JSONNodes and not only text
    return descriptor.get(key).asText();
  } else {
    return null;
  }
}

代码示例来源:origin: Texera/texera

public static String getUserScreenName(JsonNode object) {
  if (object.hasNonNull(twitterConstant.USER)) {
    return object.get(twitterConstant.USER).get(twitterConstant.SCREENNAME).asText();
  }
  return informationNotAvailable;
}

代码示例来源:origin: com.github.jasminb/jsonapi-converter

/**
 * Returns <code>true</code> in case 'DATA' note has 'ID' and 'TYPE' attributes.
 * @param dataNode relationship data node
 * @return <code>true</code> if node has required attributes, else <code>false</code>
 */
public static boolean isRelationshipParsable(JsonNode dataNode) {
  return dataNode != null && dataNode.hasNonNull(JSONAPISpecConstants.ID) && dataNode.hasNonNull(JSONAPISpecConstants.TYPE) &&
      !dataNode.get(JSONAPISpecConstants.ID).isContainerNode() && !dataNode.get(JSONAPISpecConstants.TYPE).isContainerNode();
}

代码示例来源:origin: org.n52.sensorweb.sos/coding-json

protected GeometryFactory getGeometryFactory(JsonNode node, GeometryFactory factory) throws GeoJSONException {
  if (!node.hasNonNull(CRS)) {
    return factory;
  } else {
    return decodeCRS(node, factory);
  }
}

代码示例来源:origin: jasminb/jsonapi-converter

/**
 * Returns <code>true</code> in case 'DATA' note has 'ID' and 'TYPE' attributes.
 * @param dataNode relationship data node
 * @return <code>true</code> if node has required attributes, else <code>false</code>
 */
public static boolean isRelationshipParsable(JsonNode dataNode) {
  return dataNode != null && dataNode.hasNonNull(JSONAPISpecConstants.ID) && dataNode.hasNonNull(JSONAPISpecConstants.TYPE) &&
      !dataNode.get(JSONAPISpecConstants.ID).isContainerNode() && !dataNode.get(JSONAPISpecConstants.TYPE).isContainerNode();
}

代码示例来源:origin: org.n52.series-api/spi

protected GeometryFactory getGeometryFactory(JsonNode node,
    GeometryFactory factory) throws GeoJSONException {
  if (!node.hasNonNull(JSONConstants.CRS)) {
    return factory;
  } else {
    return decodeCRS(node, factory);
  }
}

代码示例来源:origin: org.n52.sensorweb.sos/coding-json

protected SweAbstractDataComponent decodeTime(JsonNode node) throws DateTimeParseException {
  SweTime swe = new SweTime();
  if (node.hasNonNull(JSONConstants.VALUE)) {
    String value = node.path(JSONConstants.VALUE).textValue();
    swe.setValue(parseDateTime(value));
  }
  return swe.setUom(node.path(JSONConstants.UOM).textValue());
}

代码示例来源:origin: org.n52.arctic-sea/svalbard-json

protected SweAbstractDataComponent decodeTime(JsonNode node) throws DecodingException {
  SweTime swe = new SweTime();
  if (node.hasNonNull(JSONConstants.VALUE)) {
    String value = node.path(JSONConstants.VALUE).textValue();
    swe.setValue(parseDateTime(value));
  }
  return swe.setUom(node.path(JSONConstants.UOM).textValue());
}

代码示例来源:origin: org.n52.sensorweb.sos/coding-json

protected SweAbstractDataComponent decodeQuantity(JsonNode node) {
  SweQuantity swe = new SweQuantity();
  if (node.hasNonNull(JSONConstants.VALUE)) {
    swe.setValue(node.path(JSONConstants.VALUE).doubleValue());
  }
  return swe.setUom(node.path(JSONConstants.UOM).textValue());
}

代码示例来源:origin: org.n52.sensorweb.sos/coding-json

protected SweAbstractDataComponent decodeQuantityRange(JsonNode node) {
  SweQuantityRange swe = new SweQuantityRange();
  if (node.hasNonNull(JSONConstants.VALUE)) {
    double start = node.path(JSONConstants.VALUE).path(0).doubleValue();
    double end = node.path(JSONConstants.VALUE).path(1).doubleValue();
    swe.setValue(new RangeValue<Double>(start, end));
  }
  return swe.setUom(node.path(JSONConstants.UOM).textValue());
}

代码示例来源:origin: org.n52.arctic-sea/svalbard-json

protected SweAbstractDataComponent decodeCountRange(JsonNode node) {
  SweCountRange swe = new SweCountRange();
  if (node.hasNonNull(JSONConstants.VALUE)) {
    int start = node.path(JSONConstants.VALUE).path(0).intValue();
    int end = node.path(JSONConstants.VALUE).path(1).intValue();
    swe.setValue(new RangeValue<Integer>(start, end));
  }
  return swe;
}

代码示例来源:origin: org.n52.sensorweb.sos/coding-json

protected SweAbstractDataComponent decodeBoolean(JsonNode node) {
  SweBoolean swe = new SweBoolean();
  if (node.hasNonNull(JSONConstants.VALUE)) {
    swe.setValue(node.path(JSONConstants.VALUE).booleanValue());
  }
  return swe;
}

代码示例来源:origin: com.hubspot.rosetta/RosettaCore

@Test
 public void testPolymorphicStoredAsJsonBeans() throws JsonProcessingException {
  PolymorphicStoredAsJsonBean bean = new PolymorphicStoredAsJsonBean();
  bean.setAnnotatedField(new PolymorphicBeanA());

  JsonNode node = Rosetta.getMapper().valueToTree(bean);
  assertThat(node.get("annotatedField")).isNotNull();
  assertThat(node.get("annotatedField").hasNonNull("beanType"));

  assertThat(Rosetta.getMapper().treeToValue(node, PolymorphicStoredAsJsonBean.class).getAnnotatedField()).isInstanceOf(PolymorphicBeanA.class);
 }
}

相关文章