本文整理汇总了Java中com.fasterxml.jackson.databind.node.JsonNodeType.ARRAY属性的典型用法代码示例。如果您正苦于以下问题:Java JsonNodeType.ARRAY属性的具体用法?Java JsonNodeType.ARRAY怎么用?Java JsonNodeType.ARRAY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.fasterxml.jackson.databind.node.JsonNodeType
的用法示例。
在下文中一共展示了JsonNodeType.ARRAY属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: treeTraversalSolution
public void treeTraversalSolution() {
try {
ObjectMapper mapper = new ObjectMapper();
// use the ObjectMapper to read the json string and create a tree
JsonNode node = mapper.readTree(new File("Persons.json"));
Iterator<String> fieldNames = node.fieldNames();
while (fieldNames.hasNext()) {
JsonNode personsNode = node.get("persons");
Iterator<JsonNode> elements = personsNode.iterator();
while (elements.hasNext()) {
JsonNode element = elements.next();
JsonNodeType nodeType = element.getNodeType();
if (nodeType == JsonNodeType.STRING) {
out.println("Group: " + element.textValue());
}
if (nodeType == JsonNodeType.ARRAY) {
Iterator<JsonNode> fields = element.iterator();
while (fields.hasNext()) {
parsePerson(fields.next());
}
}
}
fieldNames.next();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
示例2: parseResponse
private List<FieldValues> parseResponse(final JsonNode response) {
if (response == null || response.get("fields") == null) {
throw new RuntimeException("Failed to parse JSON");
}
final JsonNode fieldsNode = response.get("fields");
if (fieldsNode.getNodeType() == JsonNodeType.OBJECT || fieldsNode.getNodeType() == JsonNodeType.ARRAY) {
final List<FieldValues> output = new ArrayList<>();
for (final JsonNode node : fieldsNode) {
try {
final FieldValues fieldValues = objectMapper.treeToValue(node, FieldValues.class);
output.add(fieldValues);
} catch (final JsonProcessingException e) {
throw new RuntimeException("Failed to parse JSON", e);
}
}
return output;
} else {
throw new RuntimeException("Failed to parse JSON");
}
}
示例3: deserialize
@Override
public List<GeoCoord> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
JsonNode node = jp.getCodec().readTree(jp);
if (JsonNodeType.ARRAY != node.getNodeType()) {
throw new IOException("Unable to instantiate new GeoCoord Path Lists from JSON!");
}
List<GeoCoord> result = new ArrayList<>(node.size());
for (int i = 0; i < node.size(); i++) {
JsonNode p = node.get(i);
double lon = p.get("longitude").asDouble();
double lat = p.get("latitude").asDouble();
result.add(new GeoCoord(lon, lat));
}
return result;
}
示例4: decodeTags
private Set<String> decodeTags(JsonNode tree, String name) {
final JsonNode n = tree.get(name);
if (n == null) {
return EMPTY_TAGS;
}
if (n.getNodeType() != JsonNodeType.ARRAY) {
return EMPTY_TAGS;
}
final List<String> tags = Lists.newArrayList();
final Iterator<JsonNode> iter = n.elements();
while (iter.hasNext()) {
tags.add(iter.next().asText());
}
return Sets.newHashSet(tags);
}
示例5: getUri
public URI getUri(int index) {
JsonNode uris = getMetadata().get("uris");
if (uris != null) {
try {
if (uris.getNodeType() == JsonNodeType.STRING) {
return new URI(uris.asText());
} else if (uris.getNodeType() == JsonNodeType.ARRAY) {
ArrayNode an = (ArrayNode)uris;
return new URI(an.get(index).asText());
}
} catch (URISyntaxException e) {
throw new RuntimeException("TD with malformed base uris");
}
} else {
throw new RuntimeException("TD without base uris field");
}
// should never be reached
throw new RuntimeException("Unexpected error while retrieving uri at index " + index);
}
示例6: getConditions
public List<ClauseNode> getConditions() {
List<ClauseNode> conditions = new ArrayList<ClauseNode>();
String comparator = root.get("condition").asText();
MatchCondition matchCondition = getMatchCondition(comparator);
boolean not = false;
if (root.get("not") != null) {
not = root.get("not").asBoolean(false);
}
JsonNode valNode = getValue();
if (valNode.getNodeType() == JsonNodeType.ARRAY) {
List<Token> tokens = new ArrayList<Token>();
for (JsonNode node : valNode) {
tokens.add(getToken(node, matchCondition));
}
conditions.add(new Condition(fieldName, new Token<List<Token>>(tokens, MatchCondition.IN), not));
} else {
conditions.add(new Condition(fieldName, getToken(valNode, matchCondition), not));
}
return conditions;
}
示例7: handleIntegerField
/**
* IntegerIndex backed fields are handled here
*
* @param fieldName name of the field
* @param node JsonNode representing the field content. This can be an array or a number
* @return Field instance
*/
private Field handleIntegerField(String fieldName, JsonNode node) {
List<Token> tokens = new ArrayList<Token>();
if (node.getNodeType() == JsonNodeType.ARRAY) {
Iterator<JsonNode> iterator = ((ArrayNode) node).elements();
while (iterator.hasNext()) {
JsonNode subNode = iterator.next();
if (subNode.getNodeType() == JsonNodeType.NUMBER) {
tokens.add(new Token<Integer>(subNode.asInt()));
}
}
} else if (node.getNodeType() == JsonNodeType.NUMBER) {
tokens.add(new Token<Integer>(node.asInt()));
}
return new Field(fieldName, tokens);
}
示例8: deserialize
public T deserialize(String message, Websocket socket) throws MessageParseException, InvalidMessageCodeException
{
JsonNode rootNode;
try {
rootNode = this.objectMapper.readTree(message);
} catch (IOException parseException) {
// TODO: check when this actually can happen, build a test-case for this
throw new MessageParseException(parseException.getMessage());
}
if (JsonNodeType.ARRAY != rootNode.getNodeType()) {
throw new MessageParseException("Message is no JSON-Array");
}
return this.deserialize(rootNode, socket);
}
示例9: readStringArray
private List<String> readStringArray(JsonNode rootNode, int position) throws MessageParseException
{
JsonNode arrayNode = rootNode.get(position);
if (null == arrayNode || JsonNodeType.ARRAY != arrayNode.getNodeType()) {
throw new MessageParseException("Expected array at position " + position);
}
List<String> stringList = new ArrayList<String>();
Iterator<JsonNode> elements = arrayNode.elements();
int iteratorPosition = 0;
while(elements.hasNext()) {
JsonNode element = elements.next();
if (JsonNodeType.STRING != element.getNodeType()) {
throw new MessageParseException("Array-Item at position " + iteratorPosition + " is no string");
}
String stringifiedElement = element.asText();
if (0 == stringifiedElement.length()) {
throw new MessageParseException("Array-Item as position " + iteratorPosition + " may not be empty");
}
stringList.add(stringifiedElement);
iteratorPosition++;
}
return stringList;
}
示例10: doEquivalent
@Override
protected boolean doEquivalent(final JsonNode a, final JsonNode b) {
/*
* If both are numbers, delegate to the helper method
*/
if (a.isNumber() && b.isNumber()) {
return numEquals(a, b);
}
final JsonNodeType typeA = a.getNodeType();
final JsonNodeType typeB = b.getNodeType();
/*
* If they are of different types, no dice
*/
if (typeA != typeB) {
return false;
}
/*
* For all other primitive types than numbers, trust JsonNode
*/
if (!a.isContainerNode()) {
return a.equals(b);
}
/*
* OK, so they are containers (either both arrays or objects due to the
* test on types above). They are obviously not equal if they do not
* have the same number of elements/members.
*/
if (a.size() != b.size()) {
return false;
}
/*
* Delegate to the appropriate method according to their type.
*/
return typeA == JsonNodeType.ARRAY ? arrayEquals(a, b) : objectEquals(a, b);
}
示例11: deserialize
@Override
public CiListRequest deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
JsonNode node = jsonParser.getCodec().readTree(jsonParser);
if (node.getNodeType() == JsonNodeType.ARRAY) {
return new CiListRequest(getIds(node));
}
else {
JsonNode attrProps = node.get("attrProps");
JsonNode altNsTag = node.get("includeAltNs");
return new CiListRequest(getIds(node.get("ids")),
attrProps == null ? null :attrProps.asText(),
altNsTag == null ? null : altNsTag.asText());
}
}
示例12: deserialize
@Override
public List<List<GeoCoord>> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
ObjectCodec codec = jp.getCodec();
JsonNode node = codec.readTree(jp);
if (JsonNodeType.ARRAY != node.getNodeType()) {
throw new IOException("Unable to instantiate new GeoCoord Path Lists from JSON!");
}
int nodeSize = node.size();
List<List<GeoCoord>> result = new ArrayList<>(nodeSize);
for (int i = 0; i < nodeSize; i++) {
JsonNode points = node.get(i);
int pointsSize = points.size();
List<GeoCoord> path = new ArrayList<>(pointsSize);
for (int j = 0; j < pointsSize; j++) {
JsonNode p = points.get(j);
double x = p.get(0).asDouble();
double y = p.get(1).asDouble();
path.add(new GeoCoord(x, y));
}
result.add(path);
}
return result;
}
示例13: createSchemaByJsonNode
private static ObjectNode createSchemaByJsonNode(JsonNode node) {
ObjectNode resultNodeNew = mapper.getNodeFactory().objectNode();
if (node.getNodeType() == JsonNodeType.OBJECT) {
ObjectNode objResult = leafNodes(node);
resultNodeNew.put(TYPE, OBJECT);
resultNodeNew.set(PROPERTIES, objResult);
} else if (node.getNodeType() == JsonNodeType.ARRAY) {
ObjectNode items = identifyAndProcessArrayNode(node);
resultNodeNew = items;
}
return resultNodeNew;
}
示例14: createModelByJsonNode
private void createModelByJsonNode(JsonNode node, String apiName, ModelBuilder rootModelBuilder){
if (node.getNodeType() == JsonNodeType.OBJECT) {
createObjectModel(node, rootModelBuilder, apiName);
models.put(apiName, rootModelBuilder);
} else if (node.getNodeType() == JsonNodeType.ARRAY) {
ArrayPropertyBuilder arrayPropertyBuilder = rootModelBuilder.withArrayProperty(apiName);
createArrayModel(node, arrayPropertyBuilder, apiName + "-item");
models.put(apiName, rootModelBuilder);
}
}
示例15: createObjectModel
private void createObjectModel(JsonNode node, ModelBuilder modelBuilder, String apiName) {
Iterator<String> fieldNames = node.fieldNames();
while (fieldNames.hasNext()) {
String field = fieldNames.next();
JsonNode leafNode = node.get(field);
if (leafNode.getNodeType() == JsonNodeType.NUMBER) {
if (leafNode.isInt() || leafNode.isLong()) {
modelBuilder.withIntegerPropertyNamed(field).withExample(leafNode.asLong());
} else if (leafNode.isFloat() || leafNode.isDouble()) {
modelBuilder.withNumberPropertyNamed(field).withExample(leafNode.asDouble());
}
} else if (leafNode.getNodeType() == JsonNodeType.BOOLEAN) {
modelBuilder.withBooleanPropertyNamed(field).withExample(leafNode.asBoolean());
} else if (leafNode.getNodeType() == JsonNodeType.STRING) {
modelBuilder.withStringPropertyNamed(field).withExample(leafNode.asText());
} else if (leafNode.getNodeType() == JsonNodeType.OBJECT) {
String refName = apiName+"-"+field;
modelBuilder.withReferencePropertyNamed(field).withReferenceTo(refName);
ModelBuilder objModelBuilder = new ModelBuilder();
createObjectModel(leafNode, objModelBuilder, refName);
models.put(refName, objModelBuilder);
}else if(leafNode.getNodeType() == JsonNodeType.ARRAY){
createArrayModel(leafNode, modelBuilder.withArrayProperty(field), apiName+"-"+field);
}
}
}