Uploaded image for project: '[Read Only] - CRISP'
  1. [Read Only] - CRISP
  2. CRISP-50

Unable to extract JSON array with scalar elements from Resource object

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Normal
    • Resolution: Fixed
    • 2.3.1
    • 13.0.0
    • None

    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

              Unassigned Unassigned
              cchen Charlie Chen
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: