Conversation
| * @return a new JsonObject. | ||
| * @since $next-version$ | ||
| */ | ||
| public static JsonObject of( |
There was a problem hiding this comment.
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.
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.
Thanks for the changes! A few more minor things.
|
@eamonnmcmanus, what do you think? |
|
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 |
ba1da0e to
30cbf35
Compare
Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
30cbf35 to
b644c6a
Compare
| * @return a new JsonObject. | ||
| * @since $next-version$ | ||
| */ | ||
| public static JsonObject of( |
There was a problem hiding this comment.
- All the overloaded methods for "of" are not needed.
- Consider using
public static JsonObject of(String... keysAndValues){
int size = keysAndValues.lenght();
if(size % 2 != 0) throw YourExceptionForInvalidParam("******");
JsonObject object = new JsonObject();
for(int i = 0; i < size; i+2;){
object.add(keysAndValues[i], keysAndValues[i+1]);
}
return object;
}
There was a problem hiding this comment.
This can only be a latest overload, like ImmutableMap.
There was a problem hiding this comment.
Why is such a requirement in the first instance?
What problems are you solving with that?
There was a problem hiding this comment.
var it = JsonObject.of("key", JsonArray.of());
it.toString() -> {"key":[]}
instead of
var it = new JsonObject()
it.add("key", new JsonArray());
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