wjyGamedev / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

JsonObject.add does not add, it sets/replaces/puts #592

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The JsonObject.add() method name and JavaDoc suggest that it is an _additive_ 
operation, but it isn't.

What steps will reproduce the problem?

        JsonObject obj = new JsonObject();
        obj.add("languages", new JsonPrimitive("en"));
        obj.add("languages", new JsonPrimitive("it"));
        System.out.println(obj.get("languages"));

What is the expected output? What do you see instead?

A programmer with no access to the code (just API and Javadoc) would probably 
expect ["en","it"] to be printed. The actual result is "it".

Suggested fix:

Deprecate/remove ALL JsonObject.add() methods and call them "set" or "put".

I know this won't happen because nothing can be removed from the API, but I 
still had to vent ;-)

Original issue reported on code.google.com by hussdl on 22 Aug 2014 at 10:29

GoogleCodeExporter commented 9 years ago
:) Yes, we should have named the methods better. And you are right that we will 
not change it because of backward compatibility. 

Original comment by inder123 on 12 Nov 2014 at 11:37