users@jersey.java.net

Re: [Jersey] Converter list problem

From: Gautam Arora <gautamsarora_at_gatech.edu>
Date: Sat, 14 Mar 2009 20:35:37 -0700 (PDT)

To recreate the scenario:
Refer to the RESTful Pet Catalog sample at
http://weblogs.java.net/blog/caroljmcdonald/archive/2008/08/a_restful_pet_c_1.html

You can download the code for this tutorial and change the @XmlRootElement
name to "things" and "thing" for ItemsConverter and ItemConverter,
respectively.

The response turns out to be:
<things>
<item>
...
</item>
</things>

whereas the correct response wouldve been:
<things>
<thing>
...
</thing>
</things>


Also the getItem() method signature seems to be correct:
    @XmlElement
    public Collection<ItemConverter> getItem() {...}

Thanks,
Gautam Arora


Gautam Arora wrote:
>
> Hi Erdinc,
> My getter method is returning a Collection of MyThingConverter.
>
> @XmlRootElement(name = "things")
> public class MyThingsConverter {
> private Collection<MyThing> entities;
> private Collection<MyThingConverter> items;
> ...
> @XmlElement
> public Collection<MyThingConverter> getMyThings() {
> ...
> return items;
> }
> ...
> }
>
> Thanks for helping me with this. Any other places you want me to check for
> in my code?
>
> Gautam
>
>
> Erdinc Yilmazel wrote:
>>
>> You should have a collection of MyThingConverter in your
>> MyThingsConverter class.
>>
>> public class MyThingsConverter {
>> private Collection<MyThing> entities; ---> private
>> Collection<MyThingConverter> entities;
>>
>> I am assuming that you have getter and setter methods for these
>> properties in MyThingsConverter class.
>> If your getter is returning Collection<MyThing>, Jaxb wouldn't care
>> about XmlRootElement annotation in MyThingConverter.
>> You should either return a collection of MyThingConverter or you
>> should also add XmlRootElement annotation to you your
>> JPA entity.
>>
>>
>>
>> On Sat, Mar 14, 2009 at 3:41 AM, Gautam Arora <gautamsarora_at_gatech.edu>
>> wrote:
>>>
>>> MyThing is an entity class and is annotated with the required JPA
>>> annotations
>>> like:
>>> @Entity
>>> @Table(name = "my_thing")
>>> @NamedQueries(...)
>>> public class MyThing {
>>> ...
>>> }
>>>
>>> Should the JPA annotations matter here because this seems to be an issue
>>> in
>>> the handling of Converter (JAXB) annotations...
>>>
>>>
>>>
>>> Erdinc Yilmazel wrote:
>>>>
>>>> How is your MyThing class annotated?
>>>>
>>>> On Sat, Mar 14, 2009 at 2:22 AM, Gautam Arora <gautamsarora_at_gatech.edu>
>>>> wrote:
>>>>>
>>>>> Hi,
>>>>> I have a Converter structure similar to....
>>>>>
>>>>> @XmlRootElement(name = "things")
>>>>> public class MyThingsConverter {
>>>>>    private Collection<MyThing> entities;
>>>>>    private Collection<MyThingConverter> items;
>>>>> .....
>>>>> }
>>>>>
>>>>> @XmlRootElement(name = "thing")
>>>>> public class MyThingConverter {
>>>>>    private MyThing entity;
>>>>> ...
>>>>> }
>>>>>
>>>>> now when i get a response using MyThingsConverter (by returning an
>>>>> object
>>>>> of
>>>>> it), my response looks like:
>>>>> <things>
>>>>>    <MyThing>
>>>>>    ....
>>>>>    </MyThing>
>>>>> </things>
>>>>>
>>>>> whereas I am expecting it to be:
>>>>> <things>
>>>>>    <thing>
>>>>>    ....
>>>>>    </thing>
>>>>> </things>
>>>>>
>>>>> so it seems that the MyThingsConverter is not properly picking up the
>>>>> correct XmlRootElement for thing which is defined by me as thing and
>>>>> going
>>>>> with the default class name of MyThing.
>>>>>
>>>>> When I just try to get a reponse from MyThingConverter, I get
>>>>> <thing>
>>>>> ...
>>>>> </thing>
>>>>>
>>>>> So, the problem seems to be when MyThingsConverter contains a list
>>>>> MyThingConverter.
>>>>>
>>>>> Any flag/setting that I need to enable in such a case?
>>>>>
>>>>> Thanks,
>>>>> Gautam
>>>>> --
>>>>> View this message in context:
>>>>> http://n2.nabble.com/Converter-list-problem-tp2476841p2476841.html
>>>>> Sent from the Jersey mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://n2.nabble.com/Converter-list-problem-tp2476841p2476981.html
>>> Sent from the Jersey mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>>
>
>

-- 
View this message in context: http://n2.nabble.com/Converter-list-problem-tp2476841p2480383.html
Sent from the Jersey mailing list archive at Nabble.com.