See discussion at http://groups.google.com/group/google-
gson/browse_thread/thread/6cfdcc56742357da
During deserialization, Gson should throw a JsonParseException if it finds
that a field marked with @Required is not present.
During serialization, Gson should always write out a field marked @Required
even if it is null.
Original issue reported on code.google.com by inder123 on 17 Oct 2008 at 10:31
Original comment by inder123 on 27 Mar 2009 at 7:36
deferred to a future release
Original comment by inder123 on 29 Sep 2009 at 9:12
It seems that @Required makes only sense in combination with !SerializeNulls.
On the other hand, @Optional would make sense in combination with SerializeNull.
Original comment by [email protected] on 18 Sep 2010 at 8:36
Original comment by inder123 on 1 Nov 2010 at 10:30
Original comment by inder123 on 3 Nov 2010 at 12:27
http://code.google.com/p/google-gson/source/detail?r=1210 provides an
experimental way to achieve this.
Original comment by inder123 on 11 Oct 2012 at 6:51
Are there any current best practices for working around this? With the current
implementation, I never have confidence that my deserialized objects have
proper values and end up having to null-check all of my object's data before
using it.
Suggestions like http://stackoverflow.com/a/14245807/128948 look promising, but
trying to see what the other options are.
Original comment by [email protected] on 11 Feb 2014 at 10:18
I'm also looking for a way to throw an Exception if a mandatory field is not in
the Json String.
Original comment by [email protected] on 28 Aug 2014 at 9:22
Count me as +1. Catching NPE much later in some distant unrelated places is
quite ugly. I have to build my custom workarounds for this, but it would be so
much better to have proper support provided by the lib.
Original comment by [email protected] on 10 Dec 2014 at 12:46
Does Gson have this feature yet ?
I am able to achieve this using this approach. This is for serialization (fail Java to Json if some @required attribute is null)
http://stackoverflow.com/questions/35587252/java-to-json-validation-using-gson/
Please use this thumbs up button to show your support. Every time someone replies with +1 we _all_ get a (useless) email.

Seems that no one cares this library. This issue should be marked as critical.
There's a library that's can help with this:
Still waiting for this feature... I want my Gson deserializing to throw an exception when a JSON doesnt have a parameter which my object do have and is either marked as @Required or not marked as @Optional. This is a big dealbreaker that Gson doesn't have this feature...
I would love to see this feature implemented as well.
Most helpful comment
Please use this thumbs up button to show your support. Every time someone replies with +1 we _all_ get a (useless) email.
