-
1. Re: NoMessageBodyWriterFoundFailure with resteasy
lvdberg Nov 10, 2010 6:13 AM (in response to sverker.sverker.abrahamsson.com)Hi,
It looks like if you're trying to return a List with objects, and RestEasy is not able to process the ArrayList (because it is not a default object for XML.marshalling).
You can do the following:
@XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "YourObjectView") public class YourObjectView { @XmlElement(required = true) protected List<YOURCLASSES> objects = new ArrayList<YOURCLASS>(); ... setter }
You add you objects to this List and return it as. The JAXB support will take care of marshalling it in the correct format.
Leo
-
2. Re: NoMessageBodyWriterFoundFailure with resteasy
jharting Nov 10, 2010 6:27 AM (in response to sverker.sverker.abrahamsson.com)Are you using EAR deployment? If so, are you putting the jars into the ${ear}/lib folder?
-
3. Re: NoMessageBodyWriterFoundFailure with resteasy
sverker.sverker.abrahamsson.com Nov 10, 2010 8:33 AM (in response to sverker.sverker.abrahamsson.com)Jozef: Yes, all jars are in ${ear}/lib folder and they are referenced by classpath in manifest of war file.
Leo: I'll try that variant to see if it works.
-
4. Re: NoMessageBodyWriterFoundFailure with resteasy
sverker.sverker.abrahamsson.com Nov 10, 2010 9:41 AM (in response to sverker.sverker.abrahamsson.com)Ok, found it. I did like this:
GenericEntity<List<PushLog>> entity = new GenericEntity<List<PushLog>>(PushLog.findAll(em)) {};
return Response.ok(entity).build();
I.e. wrapping my list in a GenericEntity, I believe this is kind of the same as the view object Leo suggests above. It removes the ArrayList type and leaves just List, which can be serialized to xml. -
5. Re: NoMessageBodyWriterFoundFailure with resteasy
lvdberg Nov 10, 2010 9:54 AM (in response to sverker.sverker.abrahamsson.com)Hi,
This is the way to do it. Be aware that you can do this without the annotations, but if you want to have more control of the output, you can add annotation on the bean attributes (or getters) and you change. An important one is XMLTransient, which excludes stuff from the process, neceassary when you have a complex object graph.
Success !
Leo
-
6. Re: NoMessageBodyWriterFoundFailure with resteasy
sverker.sverker.abrahamsson.com Nov 10, 2010 10:08 AM (in response to sverker.sverker.abrahamsson.com)Yes, I noticed that I had to use XmlTransient on a relation to prevent it to cause a LazyInitializationException from Hibernate.