Can anybody clarify me on MalformedJsonException vs GsonSyntaxException. What is the difference between these exception?

1,333 views
Skip to first unread message

Sandeep Kumar Patel

unread,
Apr 30, 2013, 6:13:03 AM4/30/13
to googl...@googlegroups.com
Exception generated for a malformed json string looks like this :-

on in thread "main" com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Expected name at line 1 column 198

In my view both classes are representing the same type of exception isn''t it?

Any pointers?

Inderjeet Singh

unread,
Apr 30, 2013, 12:52:33 PM4/30/13
to googl...@googlegroups.com
MalformedJsonException extends IOException, and hence is a checked exception. It is suitable for use when you are writing a TypeAdapter or using JsonReader/JsonWriter directly.

If you are using Gson or writing JsonSerializer/JsonDeserializer, you will use JsonParseException (superclass of JsonSyntaxException and JsonIOException). These are unchecked exceptions and dont force you to catch them in code.

HTH
Inder

----

Sandeep Kumar Patel

unread,
May 5, 2013, 12:01:55 AM5/5/13
to googl...@googlegroups.com
Thanks Inder.
Reply all
Reply to author
Forward
0 new messages