Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-6840

inconsistency in JsonSlurper return type

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.1
    • Fix Version/s: 2.3.4, 2.4.0-beta-2
    • Component/s: JSON
    • Labels:
      None

      Description

      new JsonSlurper().parseText("[]") == Collections.EMPTY_LIST
      new JsonSlurper().parseText("[1]") instanceof ArrayList
      

      Specifically, I parse some JSON to an object, then I add stuff to it, then serialise back to JSON. Since upgrading from 2.2.1 to 2.3.1 I've been tripped up by (what I assume is a change in) this behaviour.

      Why would it not return an empty ArrayList, instead of an immutable empty set, so the calling code does not need to think about whether it's empty or not?

      Guillaume Laforge said:

      The behavior isn't really specified, but it makes sense to be able to update the returned data structure for later serialization or other purposes, so I think it's worth using an empty array list instead of the empty collection

        Attachments

          Activity

            People

            • Assignee:
              guillaume Guillaume Sauthier
              Reporter:
              jechlin JAMIE ECHLIN
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: