You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Jose María Zaragoza <de...@gmail.com> on 2013/12/02 12:36:24 UTC
JSON + attributes + schema validation
Hello:
I'm using Apache CXF 2.7.3 and I've implemented a REST service by
JAX-RS API, with XML & JSON databinding support
I've enabled schema validation ( the same XSD file for both of them ),
and I use Jettison provider (1.3.4) for JSON support
When I perform a XML request, all goes fine, but when I do the same
request in JSON format , I got the next message
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.3.2.2:
Attribute 'name' is not allowed to appear in element 'field'.
The JSON payload sent is
{"requestType":{"client":{"application":"myapp","session":"000"},"event":{"code":3,"data":{"field":{"@name":"phone","$":"7774455"}}}}}
If I disabled schema validation, and 'name' attribute is not mapped
to my JAXB object
is a Jettison's problem ? is a CXF 2.7.3 problem ?
Can I use another JSON provider with schema-validation ?
Schema declaration for <event> element is
<xs:complexType name="EventType">
<xs:sequence>
<xs:element name="code" type="xs:int" />
<xs:element name="data" type="tns:DataType" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="DataType">
<xs:sequence>
<xs:element name="field" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="name" type="xs:string">
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
Thanks and regards
Re: JSON + attributes + schema validation
Posted by Jose María Zaragoza <de...@gmail.com>.
>
> I'm not sure Jettison can make a smarter decision than it already does, note
> '$' means it treats '7774455' as a mixed content.
>
> Not sure why it is not mapped. I'll be working on the next Jettison release
> this month, will have a look at this issue
>
> Sergey
Thanks for you answer.
I've could see that it's a problem with namespaces
1) if I use a namespace, all works fine
2) if I try to empty namespaces for JSON messages with
<util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
<entry key="http://ws/app/type" value=""/>
</util:map>
that only works with elements, but it doesn't with attributes
3)
if I generate JAXB classes from a schema (XSD) with
attributeFormDefault="unqualified", all works fine
I see that with attributeFormDefault="qualified" , package-info.java
doesn't generate @javax.xml.bind.annotation.XmlSchema with any
attributeFormDefault.
should it do it ? wsdl2java bug ?
Thanks and regards
Re: JSON + attributes + schema validation
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 02/12/13 11:36, Jose María Zaragoza wrote:
> Hello:
>
> I'm using Apache CXF 2.7.3 and I've implemented a REST service by
> JAX-RS API, with XML & JSON databinding support
>
> I've enabled schema validation ( the same XSD file for both of them ),
> and I use Jettison provider (1.3.4) for JSON support
>
> When I perform a XML request, all goes fine, but when I do the same
> request in JSON format , I got the next message
>
> Caused by: org.xml.sax.SAXParseException: cvc-complex-type.3.2.2:
> Attribute 'name' is not allowed to appear in element 'field'.
>
> The JSON payload sent is
>
> {"requestType":{"client":{"application":"myapp","session":"000"},"event":{"code":3,"data":{"field":{"@name":"phone","$":"7774455"}}}}}
>
>
> If I disabled schema validation, and 'name' attribute is not mapped
> to my JAXB object
> is a Jettison's problem ? is a CXF 2.7.3 problem ?
At XML level we have
<field name="phone">7774455</field>
I'm not sure Jettison can make a smarter decision than it already does,
note '$' means it treats '7774455' as a mixed content.
Not sure why it is not mapped. I'll be working on the next Jettison
release this month, will have a look at this issue
Sergey
> Can I use another JSON provider with schema-validation ?
>
>
>
> Schema declaration for <event> element is
>
> <xs:complexType name="EventType">
> <xs:sequence>
> <xs:element name="code" type="xs:int" />
> <xs:element name="data" type="tns:DataType" minOccurs="0"/>
> </xs:sequence>
> </xs:complexType>
>
> <xs:complexType name="DataType">
> <xs:sequence>
> <xs:element name="field" maxOccurs="unbounded">
> <xs:complexType>
> <xs:simpleContent>
> <xs:extension base="xs:string">
> <xs:attribute name="name" type="xs:string">
> </xs:attribute>
> </xs:extension>
> </xs:simpleContent>
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
>
>
> Thanks and regards
>