users@jersey.java.net

Re: [Jersey] XmlRootElement and plurals

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 03 Mar 2010 13:28:45 +0100

Hi Martijn,

It is a bug.

https://jersey.dev.java.net/issues/show_bug.cgi?id=361

We need to fix, which will require the developer to set a property to
enable it so we do not break on the wire backwards compatibility.

Paul.

On Mar 3, 2010, at 11:20 AM, Martijn wrote:

> Hi all,
>
> This could be a newbie question as I'm rather new to JAX-RS and
> Jersey, but I'm struggling with the pluralization when using a
> @XmlRootElement annotation.
>
> I've rewritten the objects names to clarify my point. Could be that
> I've made a typo, but you'll catch my drift as we go along. I have a
> dto class definition like
>
> @XmlRootElement(name = "myclass")
> @XmlType(propOrder={"attr1", "attr2", "attr3"})
> public class MyClassDto {
> [etc..]
> }
>
> I'm using a dto transform to make clean objects as I'm not working
> with the fullblown domain objects from the underlying business
> model. I also don't want the annotations to bleed into my domain
> classes. Wrapping from domain to dto classes in the following
> resource method fragment:
>
> @GET
> @Produces( { MediaType.TEXT_XML, MediaType.APPLICATION_XML,
> MediaType.APPLICATION_JSON })
> public List<MyClassDto> getMyclasses() {
>
> List<MyClassDto> list = new ArrayList<MyClassDto>();
> for (MyClass o : MyClassDao.instance.getModel().values()) {
> list.add(new MyclassDto(o));
>
> }
>
> return list;
> }
>
> In XML I have an output like
>
> <myClassDtoes>
> <myclass>
> <attr1>value1</attr1>
> <attr2>value2</attr2>
> <attr3>value3</attr3>
> </myclass>
> <myclass>
> <attr1>anothervalue1</attr1>
> etc..
> </myClassDtoes>
>
> I would expect another name for the wrapper element, but my original
> class name is being used and pluralized whereas the individual
> elements use the @XmlRootElement provided.
>
> Could someone help me out here? Is this standard behavior? Am I
> barking up the wrong tree?
>
> thanks for your time,
> cheers,
> Martijn
>
> --
> 31.69 nHz = once a year
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>