Uploaded image for project: 'CRISP'
  1. CRISP
  2. CRISP-51

[Backport 12.5] Unable to extract JSON array with scalar elements from Resource object

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.5.0
    • Labels:
      None
    • Similar issues:

      Description

      For example, a response with the following JSON object:

      {"list": ["a","b","c"]}
      

      The following code snippet will throw a java.lang.IllegalArgumentException: Invalid offset: 0 (size = 0), because list contains 0 child:

      Resource list = response.getValue("list", Resource.class);
      ResourceCollection collection = list.getChildren();
      

      The reason is, for an ArrayNode backed Resource, JacksonResource#getInternalAllChildren() only add elements of type ContainerNode to the children. See code snippet below:

      JsonNode value;
      int index = 0;
      
      for (Iterator<JsonNode> it = jsonNode.elements(); it.hasNext();) {
      	value = it.next();
      
      	if (value.isContainerNode()) {
      		list.add(this.toChildIndexedJacksonResource(value, ++index));
      	}
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                wko Woonsan Ko
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: