本文整理了Java中com.fasterxml.jackson.databind.JsonNode.has()
方法的一些代码示例,展示了JsonNode.has()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.has()
方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.JsonNode
类名称:JsonNode
方法名:has
[英]Method that allows checking whether this node is JSON Array node and contains a value for specified index If this is the case (including case of specified indexing having null as value), returns true; otherwise returns false.
Note: array element indexes are 0-based.
This method is equivalent to:
node.get(index) != null
NOTE: this method will return true
for explicitly added null values.
[中]方法,该方法允许检查此节点是否为JSON数组节点,并包含指定索引的值(如果是这种情况(包括指定索引的值为null的情况),返回true;否则返回false。
注意:数组元素索引是基于0的。
此方法相当于:
node.get(index) != null
注意:对于显式添加的空值,此方法将返回true
。
代码示例来源:origin: aws/aws-sdk-java
/**
* Get a string field from the JSON.
*
* @param fieldName Name of field to get.
* @return String value or null if not present.
*/
private String getString(String fieldName) {
return source.has(fieldName) ? source.get(fieldName).asText() : null;
}
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
/**
* Get name of the field generated from property.
*
* @param propertyName
* @param node
* @return
*/
public String getFieldName(String propertyName, JsonNode node) {
if (node != null && node.has("javaName")) {
propertyName = node.get("javaName").textValue();
}
return propertyName;
}
代码示例来源:origin: Activiti/Activiti
public static Set<String> gatherStringPropertyFromJsonNodes(Iterable<JsonNode> jsonNodes, String propertyName) {
Set<String> result = new HashSet<String>(); // Using a Set to filter out doubles
for (JsonNode node : jsonNodes) {
if (node.has(propertyName)) {
String propertyValue = node.get(propertyName).asText();
if (propertyValue != null) { // Just to be safe
result.add(propertyValue);
}
}
}
return result;
}
代码示例来源:origin: Activiti/Activiti
public static List<JsonNode> getAppModelReferencedProcessModels(JsonNode appModelJson) {
List<JsonNode> result = new ArrayList<JsonNode>();
if (appModelJson.has("models")) {
ArrayNode modelsArrayNode = (ArrayNode) appModelJson.get("models");
Iterator<JsonNode> modelArrayIterator = modelsArrayNode.iterator();
while (modelArrayIterator.hasNext()) {
result.add(modelArrayIterator.next());
}
}
return result;
}
代码示例来源:origin: aws/aws-sdk-java
/**
* Get a String field from the JSON.
*
* @param json JSON document.
* @param fieldName Field name to get.
* @return String value of field or null if not present.
*/
private String getTextField(JsonNode json, String fieldName) {
if (!json.has(fieldName)) {
return null;
}
return json.get(fieldName).asText();
}
代码示例来源:origin: Activiti/Activiti
public static Set<String> getAppModelReferencedModelIds(JsonNode appModelJson) {
if (appModelJson.has("models")) {
return JsonConverterUtil.gatherStringPropertyFromJsonNodes(appModelJson.get("models"), "id");
}
return Collections.emptySet();
}
代码示例来源:origin: twosigma/beakerx
@Override
public boolean canBeUsed(JsonNode n) {
return n.has("type") && n.get("type").asText().equals("CodeCell");
}
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
public String getClassName(String propertyName, JsonNode node) {
if (node != null) {
if (node.has("javaName")) {
propertyName = node.get("javaName").textValue();
} else if (generationConfig.isUseTitleAsClassname() && node.has("title")) {
String title = node.get("title").textValue();
propertyName = WordUtils.capitalize(title).replaceAll(" ", "");
}
}
return propertyName;
}
代码示例来源:origin: twosigma/beakerx
@Override
public boolean canBeUsed(JsonNode n) {
return n.has("type") && n.get("type").asText().equals("TabbedOutputContainerLayoutManager");
}
}
代码示例来源:origin: spring-projects/spring-security
private JsonNode readJsonNode(JsonNode jsonNode, String field) {
return jsonNode.has(field) ? jsonNode.get(field) : MissingNode.getInstance();
}
}
代码示例来源:origin: twosigma/beakerx
@Override
public boolean canBeUsed(JsonNode n) {
return n.has("type") && n.get("type").asText().equals("UpdatableEvaluationResult");
}
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
@Override
public JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema) {
if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations()
&& (node.has("minLength") || node.has("maxLength"))) {
JAnnotationUse annotation = field.annotate(Size.class);
if (node.has("minLength")) {
annotation.param("min", node.get("minLength").asInt());
}
if (node.has("maxLength")) {
annotation.param("max", node.get("maxLength").asInt());
}
}
return field;
}
代码示例来源:origin: twosigma/beakerx
@Override
public boolean canBeUsed(JsonNode n) {
return n.has("type") && n.get("type").asText().equals("OutputContainerCell");
}
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
@Override
public JFieldVar apply(String nodeName, JsonNode node, JsonNode parent, JFieldVar field, Schema currentSchema) {
if (ruleFactory.getGenerationConfig().isIncludeJsr303Annotations()
&& (node.has("minItems") || node.has("maxItems"))) {
JAnnotationUse annotation = field.annotate(Size.class);
if (node.has("minItems")) {
annotation.param("min", node.get("minItems").asInt());
}
if (node.has("maxItems")) {
annotation.param("max", node.get("maxItems").asInt());
}
}
return field;
}
代码示例来源:origin: twosigma/beakerx
@Override
public boolean canBeUsed(JsonNode n) {
return n.has("type") && n.get("type").asText().equals("TableDisplay");
}
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
/**
* Returns the JType for an integer field. Handles type lookup and unboxing.
*/
private JType getIntegerType(JCodeModel owner, JsonNode node, GenerationConfig config) {
if (config.isUseBigIntegers()) {
return unboxIfNecessary(owner.ref(BigInteger.class), config);
} else if (config.isUseLongIntegers() ||
node.has("minimum") && node.get("minimum").isLong() ||
node.has("maximum") && node.get("maximum").isLong()) {
return unboxIfNecessary(owner.ref(Long.class), config);
} else {
return unboxIfNecessary(owner.ref(Integer.class), config);
}
}
代码示例来源:origin: twosigma/beakerx
@Override
public boolean canBeUsed(JsonNode n) {
return n.has("type") && n.get("type").asText().equals("SimpleLayoutManager");
}
}
代码示例来源:origin: twosigma/beakerx
@Override
public boolean canBeUsed(JsonNode n) {
return n.has("type") && n.get("type").asText().equals("CyclingOutputContainerLayoutManager");
}
}
代码示例来源:origin: twosigma/beakerx
@Override
public boolean canBeUsed(JsonNode n) {
return n.has("type") && n.get("type").asText().equals("OutputContainer");
}
}
代码示例来源:origin: twosigma/beakerx
@Override
public boolean canBeUsed(JsonNode n) {
return n.has("type") && n.get("type").asText().equals("TableDisplay");
}
}
内容来源于网络,如有侵权,请联系作者删除!