That said, I looked at the exception below, and I know how to fix it.

So yes, Jackson is obviously not used and what happens now is that a default JAXB provider is asked to handle it - but it does not know what the root element of XmlType-only annotated bean is - it does not wrap automatically (compared to SOAP where the rules are specified).

Two ways to fix it:
- create an instance of CXF JAXBElementProvider, set 'marshallAsJaxbElement' property and register it - have anonymous complex types -> wadl-to-java will create XmlRootElement annotated beans in such cases; not sure though how easy it is to get such types auto-generated with the WADL generator - may be some extra JAXB properties/annotations can be set or have a prepared schema linked with WADL generator.

Sergey




On 18/08/16 16:06, Sergey Beryozkin wrote:
Hey, I'm happy trying to help but let me ask you in return,

do you think 'JacksonJsonProvider' can handle XML ?

Cheers, Sergey
On 18/08/16 14:54, J. Fiala wrote:
Hi,

I have a WADL resource which should accept both xml + json:

<resource path="/hello" id="at.hello.HelloWorldResource">
            <method name="POST">
                <request>
                    <param name="name" style="query" type="xs:string"
required="true"/>
                    <representation mediaType="application/xml"
element="mytypes:MyRequest"/>
                    <representation mediaType="application/json"
element="mytypes:MyRequest"/>
                </request>
                <response status="200">
                    <representation mediaType="application/xml"
element="mytypes:MyResponse"/>
                    <representation mediaType="application/json"
element="mytypes:MyResponse"/>
                </response>
            </method>
        </resource>

The generated Java source looks like (methods are suffixed with
Xml/Json):


@Path("/hello")
public interface HelloWorldResource{

 @POST
    @Consumes("application/xml")
    @Produces({"application/xml" })
    MyResponse postMyRequestXml(@QueryParam("name") String name,
MyRequestType myRequest);

    @POST
    @Consumes("application/json")
    @Produces({"application/json" })
    MyResponse postMyRequestJson(@QueryParam("name") String name,
MyRequestType myRequest);

}

If I call the Json method (postMyRequestJson) using JacksonProvider,
everything works.

If I call the Xml method (postMyRequestXml) using JacksonProvider, then
I get an exception:

WARNING: javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type
"at.hello.MyRequest" as an element because it is missing an
@XmlRootElement annotation]

The test is using the JacksonJsonProvider:

JacksonJsonProvider provider = new JacksonJsonProvider();
        provider.addUntouchable(Response.class);
        List<Object> providers = new ArrayList<Object>();
        providers.add(provider);
        api = JAXRSClientFactory.create(serverApp,
HelloWorldResource.class, providers);

Any ideas? Or do I have to use another provider for XML?

Best regards,
Johannes





--
Sergey Beryozkin

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

Reply via email to