sangmingming / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

suggestion: Add @Verification annotation for easy verification of POJO validity #144

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
A POJO can have a no-parameter, void return type method throwing a 
JsonParseException 
annotated with @Verification.  

If present, this will be called on the object after its fields have been 
populated.  If it determines a 
problem, it may throw a JsonParseException and the de-serialization will fail.

The motivation is to make it easier to add additional constraints on the 
validity of JSON objects, 
such as requiring that one, but not both, of two fields contain values.

Original issue reported on code.google.com by ian.clarke on 7 Aug 2009 at 11:16

GoogleCodeExporter commented 9 years ago
Seems like there is a general need for a hook for invocation after create. How 
about if we create a @PostCreate 
annotation that you apply to a method. Gson will invoke this method after 
deserializing an object. Will that work 
for your use-case?

Original comment by inder123 on 18 Aug 2009 at 5:48

GoogleCodeExporter commented 9 years ago
Yes, provided it can throw a JsonParseException or otherwise indicate that the 
object is unsuitable (eg. required 
fields are missing).

Original comment by ian.clarke on 18 Aug 2009 at 5:50

GoogleCodeExporter commented 9 years ago
We could not settle on a design of PostCreate so deferring it to a future 
release.

Original comment by inder123 on 29 Sep 2009 at 5:56

GoogleCodeExporter commented 9 years ago

Original comment by inder123 on 1 Nov 2010 at 10:33

GoogleCodeExporter commented 9 years ago

Original comment by inder123 on 3 Nov 2010 at 12:28

GoogleCodeExporter commented 9 years ago
This is essentially a subset of the features requested in issue 315.

Original comment by joel.leitch@gmail.com on 19 Apr 2011 at 9:52