-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates the
addAll
methods to have optional wrapping.
When called from the constructor, the individual items in the collection/array are wrapped as done originally before the `putAll` methods were added. However this commit changes how `putAll` works. The items are no longer wrapped in order to keep consistency with the other `put` methods. However this can lead to inconsistencies with expectations. For example code like this will create a mixed JSONArray, some items wrapped, others not: ```java SomeBean[] myArr = new SomeBean[]{ new SomeBean(1), new SomeBean(2) }; JSONArray jArr = new JSONArray(myArr); // these will be wrapped // these will not be wrapped jArr.putAll(new SomeBean[]{ new SomeBean(3), new SomeBean(4) }); ``` For consistency, it would be recommended that the above code is changed to look like 1 of 2 ways. Option 1: ```Java SomeBean[] myArr = new SomeBean[]{ new SomeBean(1), new SomeBean(2) }; JSONArray jArr = new JSONArray(); jArr.putAll(myArr); // will not be wrapped // these will not be wrapped jArr.putAll(new SomeBean[]{ new SomeBean(3), new SomeBean(4) }); // our jArr is now consistent. ``` Option 2: SomeBean[] myArr = new SomeBean[]{ new SomeBean(1), new SomeBean(2) }; JSONArray jArr = new JSONArray(myArr); // these will be wrapped // these will be wrapped jArr.putAll(new JSONArray(new SomeBean[]{ new SomeBean(3), new SomeBean(4) })); // our jArr is now consistent. ```
- Loading branch information
John J. Aylward
committed
Jul 30, 2020
1 parent
eb774b3
commit 1289cc1
Showing
1 changed file
with
46 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters