-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
JsonArray is now a List and Cloneable #2169
Conversation
If this gets approved, JsonObject will get the same treatment with the Map-Interface. |
See #683, which was substantially the same. I see at least one major problem, which is that it is not possible to implement
We might consider adding a method If you want to tackle that or any other issue, please respect the existing formatting of the project: two-space indentation; no wildcard imports; control statement bodies must use braces even if there is only one statement. See the Google Java Style Guide. |
The issue with this is that it would not protect against Also, did you delete |
Equals
Yes. I didn't wan't to touch existing implementations for the sake of backwards compatibility, but from my point of view this method could get enhanced flawlessly by using:
Given there would be an existing scenario where equals would be used on a JsonArray and a List, it already would be an extremely weird typecheck like asList
My motivation to change this were the missing "add multiple elements", and "contains"-method. Because of the added linear time complexity, converting to a List and back is just not that nice. Formatting
Sorry, I have an autoformatter and thought you guys had one too. ReplyFrom my point of view, the implementation of List is integral to what a JsonArray should be. The equals-method should be changed, and the request should get merged with the current branch. If you are not happy with this, I'm offering to create a new class JsonList, that is syntactically identical to the JsonArray, and deprecate the JsonArray (without removal). Two constructors should get offered to transfer between one and another. |
Yes, my autoformatter has deleted one unused import-statement, but I didn't want to touch a class I don't know. |
} | ||
|
||
@Override | ||
public boolean equals(Object o) { |
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.
Should get replaced by:
@Override
public boolean equals(Object o) {
return o == this || o instanceof List<?> && ((List<?>) o).equals(elements);
}
but this is debatable because of backwards-compatibility.
The google/styleguide project provides formatter configs for Eclipse (might need some additional settings tweaks to get correct formatting, see google/styleguide#273 (comment)) and IntelliJ. Additionally there is https://github.com/google/google-java-format (have not used that myself yet). Personally I just have configured the formatter to automatically adjust indentation, remove trailing whitespace and organize imports; otherwise this might cause too many differences for pull requests.
Could you please add it back? That class is definitely used. One of the main problems would probably still be binary compatibility. This was not mentioned in great detail in #683, but I think the issue here is changing |
Formatting
Thanks, I will look into that! ReflectionHelper
Is it possible to change this pull request? I didn't want to delete the file in the first place, I just wanted to remove the changes from the request. Binary Compatibility
But if another project would use the updated library, wouldn't they have to recompile either way? |
You are right. The problem would then only occur when projects have Gson as transitive dependency. In that case the third-party dependency using Gson could not be easily re-compiled. @eamonnmcmanus, how do you think should we proceed? Would you prefer the |
So, a number of thoughts here. I knew this reminded me of something. I wrote this comment probably in about 2004 when I was on the JMX team at Sun. Very similar compatibility problems arose then, specifically around the return type of So that leaves us with the I think there are two implementation strategies:
The first strategy is too fragile in my opinion. We'd have to override the 5 methods that can add or replace elements (2 × So I think the second strategy is the only viable one. I would be inclined to return a new object every time I think canonicalizing We would probably want to consider the same problem regarding |
Third strategy: Why not create a new class? These points would all be no problem with a fresh implementation.
The whole null-problem is easily avoided by using the implemented methods with their boolean return. (like |
There are two concepts: Gson's
Do you mean a Also, for future reference; it appears the force-push to this PR branch caused GitHub to erroneously think this PR was merged: However, it looks like this PR was not actually merged; I have reported this issue to GitHub. |
I don't think we want to create a new class just for this. An Regarding It looks as if this PR is borked for some reason but a new PR implementing |
Another question might be whether we want to enforce that elements are really instances of @xtay2, are you interested in giving the |
@Marcono1234 I will do it in the next few days, when I find the time :) |
@xtay2, are you still interested on working on this? No hurry in case you are still planning to do this; I just wanted to make sure this is not forgotten. |
@eamonnmcmanus, the 2.10 release notes erroneously refer to this PR here:
Could you please remove this to avoid any confusion since this PR was not merged (instead the view methods were added as mentioned above). |
Oh yes, the problem with GitHub thinking this PR has been merged, which you mentioned above, also caused it to include the PR in the auto-generated list for the release notes. I've removed it. |
The JsonArray is now a List and supports all of its operations.
Its also a Cloneable