Gson 1.7: Unable to invoke no-args constructor for class org.joda.time.DateTimeZone

5,517 views
Skip to first unread message

Todd

unread,
May 2, 2011, 1:49:58 PM5/2/11
to google-gson
Hello all,

I though no-args constructors were no longer required in 1.7. Is there
something about DateTimeZone that keeps this from working?

public static void main(String[] args) throws Exception {

Gson gson = new GsonBuilder().setPrettyPrinting().create();

String tz = "\"America/New_York\"";
Object tzObj = gson.fromJson(tz,
org.joda.time.DateTimeZone.class);
System.out.println(((DateTimeZone) tzObj).toString());

return;
}



Exception in thread "main" com.google.gson.JsonParseException:
Expecting object found: "America/New_York"
at
com.google.gson.JsonObjectDeserializationVisitor.visitFieldUsingCustomHandler(JsonObjectDeserializationVisitor.java:
100)

Thank you for any advice on this.

limpb...@gmail.com

unread,
May 3, 2011, 12:09:59 AM5/3/11
to google-gson
Your input still needs to be a JSON object, not a JSON string. If you
do 'toJson()' on the desired object you'll be able to discover the
format GSON is expecting. If you really want it to start as a string,
you'll need to write a custom type adapter.
Reply all
Reply to author
Forward
0 new messages