(Top posted due to Outlook)
Yes...I agree that having @XmlRootElement doesn't help with returning
lists but when I return a List<Person>, JAXB has no problem creating the
proper representation. (Within reason of course. There is another
thread about this being discussed concurrently.) So if my method can
return List<Person> with no problems, why does returning a Response,
who's payload is a List<Person> give me an error? That is the question
I'm posing. Here is an example:
// Works
@Produces("application/xml")
public List<Person> getPeople() {
return people;
}
// Fails
@Produces("application/xml")
public Response getPeople() {
return Response.ok(people).build();
}
Does this clarify things?
Take care,
Jeremy
________________________________
From: Craig.McClanahan_at_Sun.COM [mailto:Craig.McClanahan_at_Sun.COM]
Sent: Friday, November 14, 2008 3:01 PM
To: users_at_jersey.dev.java.net
Subject: Re: [Jersey] Unable to serialize (JAXB) when returning Response
instead of actual object types
Jeremy Whitlock wrote:
I'll bet you are running into an "interesting" detail about JAXB
that
also bit me.
I generate my JAXB classes from a schema with embedded JAXB
annotation
stuff, and (to make a long story short), JAXB does *not*
generate a
@XmlRootElement annotiation (I *think* that's the right one).
Without
this annotation, JAXB has no way to know what "outer" element to
use
around your list.
But I have that annotation on my objects. With the @XmlRootElement
annotation on a class, JAXB should be able to do this but it has
problems. That is of course unless I misunderstand what you're saying.
If you have @XmlRootElement already, I would expect a method that
returns a single Person to work correctly. That doesn't necessarily
help on returning a list.
As I haven't ever actually had that combination (model class with
@XmlRootElement, resource method returning a list of that model class),
I'll have to do some digging ... I vaguely recall reading about this
scenario in earlier message threads of this mailing list, but don't have
the details at the tip of my tongue.
Craig
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
For additional commands, e-mail: users-help_at_jersey.dev.java.net