Closed GoogleCodeExporter closed 9 years ago
Ahhhhh, sorry forgot to include GSON version.
So:
GSON version 2.0
This worked previously with
GSON Version 1.7.x
Original comment by court...@crlog.info
on 29 Nov 2011 at 10:01
I'll look into this... We're going to have a new version of Gson out by year's
end that should include a fix.
Original comment by limpbizkit
on 3 Dec 2011 at 8:33
Cool...I'll keep an eye out
Original comment by courtney...@datasift.com
on 3 Dec 2011 at 8:55
I couldn't reproduce this. Could you provide a complete example?
public void testBug382() {
String string = new GSONObjectImpl().toString();
System.out.println(string);
}
public abstract static class GSONObject<K, V> {
protected static transient Gson gson;
protected HashMap<K, V> data;
public GSONObject() {
gson = new GsonBuilder().
disableHtmlEscaping().
setPrettyPrinting().
serializeNulls().
create();
data = new HashMap<K, V>();
}
@Override
public String toString() {
return gson.toJson(this);
}
public <T> String toJson(Class<T> type) {
return gson.toJson(this, type);
}
}
public static class GSONObjectImpl extends GSONObject<String, String> {
}
Original comment by limpbizkit
on 16 Dec 2011 at 4:50
I have seen this happen. For me, this happens when Gson runs into a field of
type java.lang.Class. Typically, the reason is that I forgot to add a type
adapter for the class containing this field. Clearly, java.lang.Class fields
are not meant to be deserialized. May be a less cryptic message would help.
Original comment by inder123
on 16 Dec 2011 at 6:13
I wasn't able to re-produce it just now. The super class that contain the
static JSON object and methods as well as the sub classes have all changed
quite a bit. I tried doing it based on what I posted and remembered but it
didn't happen...
I'm not sure what inder123 means exactly but when this happened I had only that
hashmap, data as a field in the class, something like
public void put(K key, V val) {
data.put(key, val);
}
And the key was always a string, the value was occasionally POJOs that were
known to serialize just fine with GSON.
I'll try again when I get home, I'll see if I can revert to the version of the
code that had all this and try again, but unfortunately I wasn't able to
reproduce it...
Original comment by court...@crlog.info
on 16 Dec 2011 at 6:46
Inder fixed this with r1090.
Original comment by limpbizkit
on 29 Dec 2011 at 5:33
Original issue reported on code.google.com by
court...@crlog.info
on 29 Nov 2011 at 10:00