本文整理了Java中org.codehaus.jackson.JsonNode.has()
方法的一些代码示例,展示了JsonNode.has()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.has()
方法的具体详情如下:
包路径:org.codehaus.jackson.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
[中]方法,该方法允许检查此节点是否为JSON数组节点,并包含指定索引的值(如果是这种情况(包括指定索引的值为null的情况),返回true;否则返回false。
注意:数组元素索引是基于0的。
此方法相当于:
node.get(index) != null
代码示例来源:origin: apache/nifi
private JsonNode getChildNode(final JsonNode jsonNode, final RecordField field) {
if (jsonNode.has(field.getFieldName())) {
return jsonNode.get(field.getFieldName());
}
for (final String alias : field.getAliases()) {
if (jsonNode.has(alias)) {
return jsonNode.get(alias);
}
}
return null;
}
代码示例来源:origin: apache/nifi
private JsonNode getChildNode(final JsonNode jsonNode, final RecordField field) {
if (jsonNode.has(field.getFieldName())) {
return jsonNode.get(field.getFieldName());
}
for (final String alias : field.getAliases()) {
if (jsonNode.has(alias)) {
return jsonNode.get(alias);
}
}
return null;
}
代码示例来源:origin: kaaproject/kaa
/**
* Change encoding of uuids from <b>latin1 (ISO-8859-1)</b> to <b>base64</b>.
*
* @param json the json that should be processed
* @return the json with changed uuids
* @throws IOException the io exception
*/
public static JsonNode encodeUuids(JsonNode json) throws IOException {
if (json.has(UUID_FIELD)) {
JsonNode jsonNode = json.get(UUID_FIELD);
if (jsonNode.has(UUID_VALUE)) {
String value = jsonNode.get(UUID_VALUE).asText();
String encodedValue = Base64.getEncoder().encodeToString(value.getBytes("ISO-8859-1"));
((ObjectNode) jsonNode).put(UUID_VALUE, encodedValue);
}
}
for (JsonNode node : json) {
if (node.isContainerNode()) {
encodeUuids(node);
}
}
return json;
}
代码示例来源:origin: apache/incubator-gobblin
@Override
public Iterable<RecordWithMetadata<?>> convertRecord(Object outputSchema, RecordWithMetadata<byte[]> inputRecord,
WorkUnitState workUnit)
throws DataConversionException {
try {
try (JsonParser parser = jsonFactory.createJsonParser(inputRecord.getRecord())) {
parser.setCodec(objectMapper);
JsonNode jsonNode = parser.readValueAsTree();
// extracts required record
if (!jsonNode.has(RECORD_KEY)) {
throw new DataConversionException("Input data does not have record.");
}
String record = jsonNode.get(RECORD_KEY).getTextValue();
// Extract metadata field
Metadata md = new Metadata();
if (jsonNode.has(METADATA_KEY) && jsonNode.get(METADATA_KEY).has(METADATA_RECORD_KEY)) {
md.getRecordMetadata().putAll(objectMapper.readValue(jsonNode.get(METADATA_KEY).get(METADATA_RECORD_KEY), Map.class));
}
return Collections.singleton(new RecordWithMetadata<>(record, md));
}
} catch (IOException e) {
throw new DataConversionException(e);
}
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldExcludeLegacyFormatIfAsked() throws Exception
{
// Given
ExceptionRepresentation rep = new ExceptionRepresentation( new KernelException( UnknownError, "Hello" )
{
}, /*legacy*/false );
// When
JsonNode out = serialize( rep );
// Then
assertThat(out.get("errors").get(0).get("code").asText(), equalTo("Neo.DatabaseError.General.UnknownError"));
assertThat(out.get("errors").get(0).get("message").asText(), equalTo("Hello"));
assertThat(out.has( "message" ), equalTo(false));
}
代码示例来源:origin: org.apache.avro/avro
for (Field field : schema.getFields())
if (!isValidDefault(field.schema(),
defaultValue.has(field.name())
? defaultValue.get(field.name())
: field.defaultValue()))
代码示例来源:origin: kaaproject/kaa
/**
* Removes UUIDs from a json tree.
*
* @param json json tree node
*/
public static void removeUuids(JsonNode json) {
boolean containerWithId = json.isContainerNode() && json.has(UUID_FIELD);
boolean isArray = json.isArray();
boolean childIsNotArray = !(json.size() == 1 && json.getElements().next().isArray());
if (containerWithId && !isArray && childIsNotArray) {
((ObjectNode) json).remove(UUID_FIELD);
}
for (JsonNode node : json) {
if (node.isContainerNode()) {
removeUuids(node);
}
}
}
}
代码示例来源:origin: kaaproject/kaa
} else {
for (JsonNode child : object.get(DEPENDENCIES)) {
if (!child.isObject() || !child.has(FQN) || !child.get(FQN).isTextual()
|| !child.has(VERSION) || !child.get(VERSION).isInt()) {
throw new IllegalArgumentException("Illegal dependency format!");
} else {
代码示例来源:origin: neo4j/neo4j
assertEquals( "one entry", initialData + 1, data.size() );
JsonNode entry = data.get( 0 );
assertTrue( "entry has row", entry.has( "row" ) );
assertTrue( "entry has graph", entry.has( "graph" ) );
JsonNode nodes = entry.get( "graph" ).get( "nodes" );
JsonNode rels = entry.get( "graph" ).get( "relationships" );
代码示例来源:origin: sismics/reader
/**
* Checks if the JSON node contains the properties (not null).
*
* @param n JSON node to check
* @param name Name of the property
*/
public static void validateJsonRequired(JsonNode n, String name) throws Exception {
if (!n.has(name)) {
throw new Exception(MessageFormat.format("{0} must be set", name));
}
}
代码示例来源:origin: io.snamp/json-helpers
private static OpenType<?> deserializeComplexType(final JsonNode json) throws JsonProcessingException{
if(json.has(IS_PRIMITIVE_FIELD) && json.has(ARRAY_ELEMENT_FIELD) && json.has(DIMENSIONS_FIELD)) //array type
return deserializeArrayType(json);
else if(json.has(ITEMS_FIELD)) //composite type
return deserializeCompositeType(json);
else if(json.has(INDEX_FIELD) && json.has(ROW_TYPE_FIELD)) //tabular type
return deserializeTabularType(json);
else
throw new OpenTypeProcessingException();
}
代码示例来源:origin: lordofthejars/nosql-unit
private JsonNode valueNode(JsonNode element) {
if (element.has(KeyValueTokens.VALUE_TOKEN)) {
return element.path(KeyValueTokens.VALUE_TOKEN);
} else {
throw new IllegalArgumentException("Given dataset does not contain "+KeyValueTokens.VALUE_TOKEN+" token.");
}
}
代码示例来源:origin: lordofthejars/nosql-unit
private String implementationKeyClass(JsonNode element) {
String implementationValue = NO_IMPLEMENTATION_PROVIDED;
if (element.has(KeyValueTokens.IMPLEMENTATION_KEY_TOKEN)) {
implementationValue = element.path(KeyValueTokens.IMPLEMENTATION_KEY_TOKEN).getTextValue();
}
return implementationValue.trim();
}
代码示例来源:origin: lordofthejars/nosql-unit
private String implementationClass(JsonNode element) {
String implementationValue = NO_IMPLEMENTATION_PROVIDED;
if (element.has(KeyValueTokens.IMPLEMENTATION_TOKEN)) {
implementationValue = element.path(KeyValueTokens.IMPLEMENTATION_TOKEN).getTextValue();
}
return implementationValue.trim();
}
代码示例来源:origin: mobi.boilr/libdynticker
@Override
protected String getTicker(Pair pair) throws IOException {
if(!pairs.contains(pair))
throw new IOException("Invalid pair: " + pair);
JsonNode node = readJsonFromUrl("https://api.coinsecure.in/v0/noauth/lasttrade");
if(node.has("error"))
throw new IOException(node.get("error").asText());
else
return parseTicker(node, pair);
}
代码示例来源:origin: lordofthejars/nosql-unit
private Object keyValue(JsonNode element) throws JsonParseException, JsonMappingException, IOException, ClassNotFoundException {
Object keyValue;
if (element.has(KeyValueTokens.KEY_TOKEN)) {
String implementationKey = implementationKeyClass(element);
keyValue = readElement(element.path(KeyValueTokens.KEY_TOKEN), implementationKey);
} else {
throw new IllegalArgumentException("Given dataset does not contain "+KeyValueTokens.KEY_TOKEN+" token.");
}
return keyValue;
}
代码示例来源:origin: mobi.boilr/libdynticker
@Override
protected String getTicker(Pair pair) throws IOException {
JsonNode node = readJsonFromUrl(peer + "getTrades&lastIndex=0&asset=" + pair.getMarket());
if(node.has("errorCode"))
throw new IOException(node.get("errorDescription").asText());
return parseTicker(node, pair);
}
代码示例来源:origin: mobi.boilr/libdynticker
@Override
protected String getTicker(Pair pair) throws IOException {
// https://api.bitso.com/v2/ticker?book=btc_mxn
JsonNode node = readJsonFromUrl("https://api.bitso.com/v2/ticker?book=" +
pair.getCoin() + "_" + pair.getExchange());
if(node.has("error"))
throw new IOException(node.get("error").get("message").asText());
return parseTicker(node, pair);
}
代码示例来源:origin: mobi.boilr/libdynticker
@Override
protected String getTicker(Pair pair) throws IOException {
JsonNode node = readJsonFromUrl("https://coinut.com/api/tick/" +
pair.getCoin() + pair.getExchange());
if(node.has("error")) {
throw new IOException(node.get("error").asText());
} else {
return parseTicker(node, pair);
}
}
代码示例来源:origin: mobi.boilr/libdynticker
@Override
protected String getTicker(Pair pair) throws IOException {
JsonNode node = readJsonFromUrl("https://www.galmarley.com/prices/prices.json?version=v2&interval=5&batch=Update&securityId="
+ pair.getCoin() + "&valuationSecurityId=" + pair.getExchange());
if(node.has("latestPrice")) {
return parseTicker(node, pair);
} else {
throw new IOException("Invalid pair: " + pair);
}
}
内容来源于网络,如有侵权,请联系作者删除!