Fail on unknown property

652 views
Skip to first unread message

Simon Lodal

unread,
Nov 29, 2012, 2:48:18 AM11/29/12
to googl...@googlegroups.com
If the input json data has unknown fields I need to fail or handle it somehow. Is there any way to do that?

Is it true that gson is by design a sloppy parser?

Inderjeet Singh

unread,
Nov 30, 2012, 4:47:33 AM11/30/12
to googl...@googlegroups.com
Gson by design is a lenient parser. If you need to fail on unknown fields, you need to write a custom JsonDeserializer or TypeAdapter for each class where you need strict parsing.

Alternatively, you can write a TypeAdapterFactory that does this for a set of classes that you care about.

HTH
Inder

fw...@fwber.com

unread,
Apr 8, 2013, 5:32:40 AM4/8/13
to googl...@googlegroups.com
I also need a way to log unknown (renamed) fields instead of silently discarding them.

Is there an example anywhere of how to do this?
Reply all
Reply to author
Forward
0 new messages