-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
DRAFT: (JSONArray).toList() breaks format of entries #810
Conversation
… it will support the streams but also all other functionality of a list
# Conflicts: # src/main/java/org/json/JSONObject.java
Can't be accepted because of broken unit tests. It's recommended to run the unit tests locally before submitting a pull request, to catch problems like this. In this case, changing the JSONArray implements type is likely to break some existing projects that use JSON-Java. |
@stleary I open the PR as a draft for discussion to so my suggestion as code. I didn't give time to the tests because of this. If we proceed with this implementation then I will fix the tests also I will add test methods for the new methods. Can you please explain to me a case that this change isn't backward compatible? Because the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding a bunch of little comments, here is a single one.
Overall I don't think these overrides should NOT be calling anything directly on myArrayList
. Each of the overrides should be using the similar JSONArray.put
, set
, addAll
, etc. methods that already exist and have been tested.
Items that are thoroughly new to the interface like subList
should be implemented in a way that the sub-list return is also a valid JSONArray.
Similarly, I don't like the existing iterator implementation that just exposes the underlying collection iterator. Changes to this implementation may be out of scope for this PR, but directly exposing the underlying data may not be the expected behavior by callers. My personal preference would be that anything returned by using the iterator would be a valid JSON value (i.e. Map
s would be returned as JSONObject
, Double
values would not return is they are NaN
, etc.)
@ZachsCoffee Good point. In the past, PRs have only been used for an actual request to update the repo, but a draft or work-in-progress designation makes sense. I will update the Wiki at some point on how to do this. Probably something like a |
Thank you @stleary. Yes, it will be good to have draft PRs. Yes, you are right, as I see from the broken tests that there is some possibility of breaking changes. But I think it's a rare case. To fall into this case, they should have overload methods that accept Iterable and other methods List for the same argument position, and when they pass a @johnjaylward I see your point. The changes that you describe is certain to be breaking changes :P So because the above + is getting out of scope I think it will better to have a new |
Closing due to no activity in the past year |
fix for: #737
PR for discussion:
I suggest making the
JSONArray
class to implement theList
because contains the functionality of a list also is powered by anArrayList
which is aList
.By making it a
List
it can be used by others like any otherList
class making it more useful.Also automatically contains the
stream()
method that we want.If we proceed with this approach I will add tests for the new methods.