You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by fm...@apache.org on 2014/03/20 11:54:23 UTC
git commit: [OLINGO-175] fix for json array property retrieve
Repository: incubator-olingo-odata4
Updated Branches:
refs/heads/olingo200 4431a80db -> 06d5264ee
[OLINGO-175] fix for json array property retrieve
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/commit/06d5264e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/tree/06d5264e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/diff/06d5264e
Branch: refs/heads/olingo200
Commit: 06d5264ee9f9d040aaa35c489b35f6d1b2807e44
Parents: 4431a80
Author: fmartelli <fa...@gmail.com>
Authored: Thu Mar 20 11:54:11 2014 +0100
Committer: fmartelli <fa...@gmail.com>
Committed: Thu Mar 20 11:54:11 2014 +0100
----------------------------------------------------------------------
.../apache/olingo/fit/utils/JSONUtilities.java | 29 ++++++++++----------
1 file changed, 15 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/06d5264e/fit/src/main/java/org/apache/olingo/fit/utils/JSONUtilities.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/JSONUtilities.java b/fit/src/main/java/org/apache/olingo/fit/utils/JSONUtilities.java
index a58f3d2..79d2d8f 100644
--- a/fit/src/main/java/org/apache/olingo/fit/utils/JSONUtilities.java
+++ b/fit/src/main/java/org/apache/olingo/fit/utils/JSONUtilities.java
@@ -181,7 +181,7 @@ public class JSONUtilities extends AbstractUtilities {
throws Exception {
final ObjectMapper mapper = new ObjectMapper();
final JsonNode srcNode = mapper.readTree(src);
- JsonNode node = getProperty(srcNode, path, 0);
+ JsonNode node = getProperty(srcNode, path);
return IOUtils.toInputStream(node.asText());
}
@@ -202,8 +202,11 @@ public class JSONUtilities extends AbstractUtilities {
propertyNode.put(JSON_ODATAMETADATA_NAME, ODATA_METADATA_PREFIX + edmType);
}
- JsonNode jsonNode = getProperty(srcNode, path, 0);
- if (jsonNode.isObject()) {
+ JsonNode jsonNode = getProperty(srcNode, path);
+
+ if (jsonNode.isArray()) {
+ propertyNode.put("value", (ArrayNode) jsonNode);
+ } else if (jsonNode.isObject()) {
propertyNode.putAll((ObjectNode) jsonNode);
} else {
propertyNode.put("value", jsonNode.asText());
@@ -218,20 +221,18 @@ public class JSONUtilities extends AbstractUtilities {
return res;
}
- private JsonNode getProperty(final JsonNode node, final List<String> path, final int index)
+ private JsonNode getProperty(final JsonNode node, final List<String> path)
throws NotFoundException {
- final Iterator<Map.Entry<String, JsonNode>> iter = node.fields();
- while (iter.hasNext()) {
- final Map.Entry<String, JsonNode> entry = iter.next();
- if (path.get(index).equals(entry.getKey())) {
- if (path.size() - 1 == index) {
- return entry.getValue();
- } else {
- return getProperty(entry.getValue(), path, index + 1);
- }
+
+ JsonNode propertyNode = node;
+ for (int i = 0; i < path.size(); i++) {
+ propertyNode = propertyNode.get(path.get(i));
+ if (propertyNode == null) {
+ throw new NotFoundException();
}
}
- throw new NotFoundException();
+
+ return propertyNode;
}
public InputStream addJsonInlinecount(