mirror of
https://github.com/apache/olingo-odata4.git
synced 2025-02-06 10:09:25 +00:00
[OLINGO-175] fix for json array property retrieve
This commit is contained in:
parent
4431a80db5
commit
06d5264ee9
@ -181,7 +181,7 @@ public class JSONUtilities extends AbstractUtilities {
|
|||||||
throws Exception {
|
throws Exception {
|
||||||
final ObjectMapper mapper = new ObjectMapper();
|
final ObjectMapper mapper = new ObjectMapper();
|
||||||
final JsonNode srcNode = mapper.readTree(src);
|
final JsonNode srcNode = mapper.readTree(src);
|
||||||
JsonNode node = getProperty(srcNode, path, 0);
|
JsonNode node = getProperty(srcNode, path);
|
||||||
return IOUtils.toInputStream(node.asText());
|
return IOUtils.toInputStream(node.asText());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,8 +202,11 @@ public class JSONUtilities extends AbstractUtilities {
|
|||||||
propertyNode.put(JSON_ODATAMETADATA_NAME, ODATA_METADATA_PREFIX + edmType);
|
propertyNode.put(JSON_ODATAMETADATA_NAME, ODATA_METADATA_PREFIX + edmType);
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonNode jsonNode = getProperty(srcNode, path, 0);
|
JsonNode jsonNode = getProperty(srcNode, path);
|
||||||
if (jsonNode.isObject()) {
|
|
||||||
|
if (jsonNode.isArray()) {
|
||||||
|
propertyNode.put("value", (ArrayNode) jsonNode);
|
||||||
|
} else if (jsonNode.isObject()) {
|
||||||
propertyNode.putAll((ObjectNode) jsonNode);
|
propertyNode.putAll((ObjectNode) jsonNode);
|
||||||
} else {
|
} else {
|
||||||
propertyNode.put("value", jsonNode.asText());
|
propertyNode.put("value", jsonNode.asText());
|
||||||
@ -218,20 +221,18 @@ public class JSONUtilities extends AbstractUtilities {
|
|||||||
return res;
|
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 {
|
throws NotFoundException {
|
||||||
final Iterator<Map.Entry<String, JsonNode>> iter = node.fields();
|
|
||||||
while (iter.hasNext()) {
|
JsonNode propertyNode = node;
|
||||||
final Map.Entry<String, JsonNode> entry = iter.next();
|
for (int i = 0; i < path.size(); i++) {
|
||||||
if (path.get(index).equals(entry.getKey())) {
|
propertyNode = propertyNode.get(path.get(i));
|
||||||
if (path.size() - 1 == index) {
|
if (propertyNode == null) {
|
||||||
return entry.getValue();
|
throw new NotFoundException();
|
||||||
} else {
|
|
||||||
return getProperty(entry.getValue(), path, index + 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new NotFoundException();
|
|
||||||
|
return propertyNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream addJsonInlinecount(
|
public InputStream addJsonInlinecount(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user