-
Notifications
You must be signed in to change notification settings - Fork 4.4k
JsonArray.of & JsonObject.of #2927
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
base: main
Are you sure you want to change the base?
Conversation
Marcono1234
left a comment
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.
| * @return a new JsonObject. | ||
| * @since $next-version$ | ||
| */ | ||
| public static JsonObject of( |
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.
These of overloads make it a bit verbose, though I guess there is no better way at the moment and Guava and the JDK do it like this as well.
The other alternative would be to only have maybe of 1-3 and for the rest require the user to use a different approach, e.g. the above mentioned of(Map).
Would be good to wait for the opinion of one of the project members.
Marcono1234
left a comment
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.
Thanks for the changes!
I think you slightly need to adjust the types so that subtypes of JsonElement don't cause issues. See comments.
|
@Marcono1234 Can we use some codegen technique to generate factory methods for them? I don't know if we can modify an existing class, for example, adding a static method. |
|
Which factory methods are you referring to? Sorry if my previous comment was a bit confusing; I just meant that the methods you added should use Or do you want to use code generation to generate the |
Marcono1234
left a comment
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.
Thanks for the changes! A few more minor things.
|
@eamonnmcmanus, what do you think? |
|
|
||
| /** Creates an empty JsonArray. */ | ||
| @SuppressWarnings("deprecation") // superclass constructor | ||
| private JsonArray(ArrayList<JsonElement> elements) { |
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note
JsonElement.JsonElement
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
|
I will probably split this PR into 2 or more for easier review & merging. |
|
Sorry for not responding earlier. I completely agree that the |
|
I think extensions about |
Generally we have something like DTO list/map which can't be simply parsed into JSON tree without serializer. If we only allow Map to JsonObject, this API might be not so useful. |
I think what you are describing is what Gson already does with its |
Purpose
Like Java 9 and Guava.
Description
closes #2923
Checklist
This is automatically checked by
mvn verify, but can also be checked on its own usingmvn spotless:check.Style violations can be fixed using
mvn spotless:apply; this can be done in a separate commit to verify that it did not cause undesired changes.null@since $next-version$(
$next-version$is a special placeholder which is automatically replaced during release)TestCase)mvn clean verify javadoc:jarpasses without errors