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