Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for JSONArray.putAll methods #552

Merged
merged 6 commits into from Aug 1, 2020

Commits on Jul 30, 2020

  1. Update for JSONArray.putAll methods

    * Adds a copy constructor for JSONArray
    * Updates the JSONArray.addAll(Object) method to be more lenient
    * Adds support for JSONArray.putAll of generic Iterables
    * Adds support for JSONArray.putAll of another JSONArray
    John J. Aylward committed Jul 30, 2020
    Copy the full SHA
    f37c2d6 View commit details
    Browse the repository at this point in the history
  2. update some javadoc

    John J. Aylward committed Jul 30, 2020
    Copy the full SHA
    3c9573c View commit details
    Browse the repository at this point in the history
  3. remove clone

    John J. Aylward committed Jul 30, 2020
    Copy the full SHA
    c175a9e View commit details
    Browse the repository at this point in the history
  4. Copy the full SHA
    5d828d2 View commit details
    Browse the repository at this point in the history
  5. 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:
    ```Java
    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.
    ```
    John J. Aylward committed Jul 30, 2020
    Copy the full SHA
    f35194b View commit details
    Browse the repository at this point in the history
  6. Copy the full SHA
    d30ecad View commit details
    Browse the repository at this point in the history