Hi
On 09/10/13 18:42, tomstark wrote:
Hello,
We have a REST API that was originally developed using XSDs with CXF 2.5.2
using XML as the payload. To make the API flexible, objects are created
with a <xs:any> array at the end of each object to allow for backward
compatibility. Here is a schema example:
<xs:complexType name="someType">
<xs:sequence>
<xs:element name="someInt" type="xs:int">
</xs:element>
<xs:any minOccurs="0" maxOccurs="unbounded"
namespace="##other" processContents="lax"/>
</xs:sequence>
</xs:complexType>
We would like to add JSON support to the same API but have a problem in that
the object definitions in XSD use xs:sequence thus forcing the JSON to be
ordered, which is not guaranteed from the client.
Do you mean it is not guaranteed from JSON client ? If so, do you mean
that a new content covered by xsd:any can get in front of someInt ?
I have researched what else can be done from the XSD and unfortunately, the
<xs:all> cannot be used in place of the <xs:sequence> since it doesn't allow
the <xs:any> element.
I would really like schema validation to be turned on to protect the server
but this seems to be incompatible with allowing unordered JSON.
In our case, the order of construction of the POJOs is not important but
rather element types and restrictions are important.
Since it does not appear to be possible to solve this problem from a schema
standpoint, is it a bad idea to have the schema validation ignore sequencing
only?
Currently, I have upgraded to CXF 2.7.5, with Jettison 1.3.3.
well, assuming you'd like to support JSON clients which are not
guaranteed to send JSON with some specific order in place (and
specifically, they can add the extension data in front of the payloads,
etc), then what you can try to do is have a schema added to JSONProvider
which will not allow the extensions, so that the schema validates for a
very specific content only, like someInt, and then also configure
JSONProvider to drop the extension data which is known to exist, see
http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-CustomizingJAXBXMLandJSONinputandoutput
(inDropElements map property)
Not sure if it will help in your case though...
Sergey
Looking for some suggestions of how to resolve this issue or is this a case
of trying to make a round peg fit a square hole?
Any help is greatly appreciated.
Thanks,
Tom
--
View this message in context:
http://cxf.547215.n5.nabble.com/Can-unordered-JSON-work-with-XML-sequence-with-validation-tp5734874.html
Sent from the cxf-user mailing list archive at Nabble.com.