Hi On 11/07/12 06:48, S K wrote:
Hello, I have a REST service which supports JSON requests. When an element of the JSON object contains more than one of the same elements (e.g. "a") and the element is not defined as a collection, the last element found in the request is set to the instance of the annotated bean for that element and the first one is ignored/overwritten. The schema validation does not catch this is it would for an equivalent XML request. For example, below "a" is an element which is defined once in the annotated class but when it appears more than once in the request, "a" will be set to 2. Is there a way I can have my service recognize this JSON request contains more than one "a" element, which is not allowed before allowing the request to continue? The requests are being validated by an XSD. I'm using CXF 2.6.1.{ "SomeRequest": { "a":1, "a":2, "b":2 }} this is how the field is defined in the request class SomeRequest @XmlElement(name = "a" , required=true) private Long a; Schema element defined as: <xs:element name="a" type="xs:long"/>
The problem was in Jettison which I've just fixed. Jettison can not stream at the moment so the values having identical keys were simply overwritten. So the good news is that Jettison 1.3.2 will have this issue fixed.
The possible workaround is to extend JSONProvider and wrap the reader it creates with the custom reader which will do its own enforcement, example, it will block the payloads which will have more than one 'a' element...
thanks, Sergey
Thanks! Steve
