shau-lok / google-gson

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

The javadoc for JsonDeserializer is out of date or incorrect (I'm pretty sure) #371

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The section at 
http://google-gson.googlecode.com/svn-history/r88/trunk/docs/javadocs/com/google
/gson/JsonDeserializer.html is currently:

"""
class IdDeserializer implements JsonDeserializer<Id>() {
  public Id fromJson(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    return (Id) new Id((Class)typeOfT, id.getValue());
}

You will also need to register IdDeserializer with Gson as follows:
Gson gson = new GsonBuilder().registerTypeAdapter(new 
IdDeserializer()).create();
"""

and should be, with the following corrections:
  remove "()"  
  "fromJson" -> "deserialize"
  remove "(Id)" since it seems to be unnecessary (I didn't check)
  "id.getValue()" should be "json.getAsString()"?
  add "Id.class" argument to "registerTypeAdapter"

"""
class IdDeserializer implements JsonDeserializer<Id> {
  public Id deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    return new Id((Class) typeOfT, json.getAsString());
}

You will also need to register IdDeserializer with Gson as follows:
Gson gson = new GsonBuilder().registerTypeAdapter(Id.class, new 
IdDeserializer()).create();
"""

Cheers,
-Greg-

Original issue reported on code.google.com by borisb0...@gmail.com on 24 Oct 2011 at 2:35

GoogleCodeExporter commented 9 years ago
Oops, realized I was using a google-found link that might be for an older 
revision, but the docs at 
http://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/index.html look 
the same.

Original comment by borisb0...@gmail.com on 24 Oct 2011 at 2:39

GoogleCodeExporter commented 9 years ago
Already fixed in source control.

Original comment by limpbizkit on 24 Oct 2011 at 3:41

GoogleCodeExporter commented 9 years ago
Thanks for pointing me to that, I'll check what's checked in next time.

It appears as though the extra () and possibly unnecessary cast are still there 
(where there == 
http://www.google.com/codesearch#1W0hTXRl0vg/trunk/gson/src/main/java/com/google
/gson/JsonDeserializer.java&q=JsonDeserializer%20package:http://google-gson%5C.g
ooglecode%5C.com) but these are minor in comparison to the incorrect method 
names and parameters. 

Original comment by borisb0...@gmail.com on 24 Oct 2011 at 5:01