users@jersey.java.net

[Jersey] Re: Problem with getting data from a list with Jersey

From: Eric Reagan <reaganej_at_gmail.com>
Date: Mon, 13 Jun 2011 11:21:12 -0400

Hello Arul,
    I tried adding the @XmlRootElement to my Airport class and I still can't
get anything returned except an empty list. If I do something like

public class Airport
{
    ...

    private List<Flight> flights;

    ...
    @XmlElementWrapper(name="flightList"
    @XmlElement(name="flight")

> private List<Flight> flights;
>
> ...
>
> public List<Flight> getFlights()
> {
> return flights;
> }
>
> public void setFlights(List<Flight> flights)
> {
> this.flights = flights;
> }
>
>
> }



    I get a non empty list of flights but I can't do anything with that list
because of the class has two properties of the same name exception.

Thank you,



On Sun, Jun 12, 2011 at 11:26 PM, Arul Dhesiaseelan <aruld_at_acm.org> wrote:

> I believe you just need to add @XmlRootElement to your Airport class to fix
> the JAXB exception. This should work:
>
> @XmlRootElement
>
> public class Airport {
>
> private List<Flight> flights;
>
> @XmlElementWrapper(name = "flightList")
> @XmlElement(name = "flight")
> public List<Flight> getFlights() {
> return flights;
> }
>
> public void setFlights(List<Flight> flights) {
> this.flights = flights;
> }
>
> public static class Flight {
> private String name;
>
> public String getName() {
> return name;
> }
>
> public void setName(String name) {
> this.name = name;
> }
> }
>
> }
>
> -Arul
>
>
> On Fri, Jun 10, 2011 at 11:45 AM, Eric Reagan <reaganej_at_gmail.com> wrote:
>
>> Hello,
>> I have a class which is like
>> @XmlAccessorType( XmlAccessType.PUBLIC_MEMBER )
>> public class Airport
>> {
>> ...
>>
>> private List<Flight> flights;
>>
>> ...
>> @XmlElementWrapper(name="flightList")
>> @XmlElement(name="flight})
>> private List<Flight> flights;
>>
>> ...
>>
>> public List<Flight> getFlights()
>> {
>> return flights;
>> }
>>
>> public void setFlights(List<Flight> flights)
>> {
>> this.flights = flights;
>> }
>>
>>
>> }
>>
>> and I am getting a class has two properties of the same name about the
>> getFlights() method and the flights variable. The interesting problem I am
>> having is in my GUI code when I call getFlights() method I have the class
>> has two properties of the same name error. If I change my code to look like
>>
>> public class Airport
>> {
>> ...
>>
>> private List<Flight> flights;
>>
>> ...
>> @XmlElementWrapper(name="flightList")
>> @XmlElement(name="flight})
>> private List<Flight> flights;
>>
>> ...
>>
>> public List<Flight> getFlights()
>> {
>> return flights;
>> }
>>
>> public void setFlights(List<Flight> flights)
>> {
>> this.flights = flights;
>> }
>>
>>
>> }
>>
>>
>> Everything seams to work fine but the getFlights() will always return
>> an empty list. My flight class looks like
>> @XmlRootElement
>> public class Flight
>> {
>> ...
>> }
>>
>> I don't understand what I am doing wrong when trying to my Airport
>> object via a Jersey GET request and either I don't get a list of flights or
>> I get a class has two properties of the same name exception.
>>
>> Thank you,
>>
>> --
>> Eric Reagan
>>
>
>
>
>
>


-- 
Eric Reagan