Auto Conversion to XML from Java Object is not working in Restlet

192 Views Asked by At

I have a method

@Get("xml")
public User getUser()
{
 return new User();
}

In this case when calling this method browser is showing null as response. I have also annotated the User class with @XmlRootElement Tag.

It is working fine for Json transformation

@Get("json")
public User getUser()
{
 return new User();
}

Please help me where I am going wrong

1

There are 1 best solutions below

3
Thierry Templier On BEST ANSWER

You can leverage the converter service of Restlet for automatic transformation of objects to payload and payload to objects.

I don't know what you use for JSON, but for XML and JAXB you need to add the org.restlet.ext.jaxb jar file corresponding to the JAXB extension of Restlet.

Doing that a converter for JAXB will be automatically add into the Restlet engine to actually handle such beans.

Hope it helps you, Thierry