You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by David Hay <da...@enstratius.com> on 2013/09/18 20:44:29 UTC

Prevent invalid objects when passing objects to REST call

I have switched some of our REST methods to receive objects (via JSON)
rather than form params.

What is the suggested pattern to prevent invalid objects being received?  I
assume that the default constructor is called followed by setters on the
object?

cheers,

David

Re: Prevent invalid objects when passing objects to REST call

Posted by Sergey Beryozkin <sb...@gmail.com>.
On 18/09/13 19:44, David Hay wrote:
> I have switched some of our REST methods to receive objects (via JSON)
> rather than form params.
>
> What is the suggested pattern to prevent invalid objects being received?  I
> assume that the default constructor is called followed by setters on the
> object?

If you use CXF JSONProvider then you can pass it a list of XSD schema 
locations (schemaLocations property), this works because the actual 
object population is driven by JAXB.
Or you can register a custom XMLStreamReader too and do the custom 
validation of the data reported by Jettison, I can provider more info if 
your are interested.

You can also register a custom MessageBodyReader which simply delegates 
to your chosen JSON provider (Jackson, etc), and validates the object in 
its readFrom method, after the actual provider creates it

Sergey



>
> cheers,
>
> David
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com