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

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

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Normal
    • Resolution: Fixed
    • None
    • 2.5.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
              wko Woonsan Ko (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: