Gson does NOT throw exception when unknown Enum values are deserialized.

970 views
Skip to first unread message

Todd Chapman

unread,
Sep 5, 2013, 3:09:27 PM9/5/13
to googl...@googlegroups.com
Hi all,

I have a gson object initialized with:

    Gson gson = new Gson();

When I call gson.fromJson(json_string, MyClass.class)  I expect a exception to be thrown since json_string contains an invalid value for an enum member. However no exception is thrown.

Do I need to configure the Gson object to be more strict in its deserialization?

Thanks!

-Todd

Brandon Mintern

unread,
Sep 20, 2013, 2:30:00 PM9/20/13
to google-gson
I just ran into this same issue. I have attached a TypeAdapterFactory that you can register which will throw a JsonParseException wrapping an IllegalArgumentException when there is a bad enum value.


--
You received this message because you are subscribed to the Google Groups "google-gson" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-gson...@googlegroups.com.
To post to this group, send email to googl...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-gson.
For more options, visit https://groups.google.com/groups/opt_out.

EnumAdapterFactory.java
Reply all
Reply to author
Forward
0 new messages