1

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

Thierry Templier
  • 182,931
  • 35
  • 372
  • 339
Nishant Modi
  • 533
  • 1
  • 5
  • 17

1 Answers1

0

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

Thierry Templier
  • 182,931
  • 35
  • 372
  • 339
  • I have this jar in my classpath still it is not working for me. I guess it is converting the object to xml but resulting in null value for object – Nishant Modi Jan 12 '16 at 05:04
  • I just added ObjectFactory Class annotated with `@XMLRegistory` to register User Object and now every thing is working.Still surprised why this is needed – Nishant Modi Jan 12 '16 at 09:42
  • `package com.rest.xml; import javax.xml.bind.annotation.XmlRegistry; @XmlRegistry public class ObjectFactory { public User create() { return new User(); } }` Added this class in my package – Nishant Modi Jan 13 '16 at 05:00