Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.3.1
-
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