Hi Arul,
I tried both of these and still can't get around the whole issue of
getting an empty list of flights when there is data there. I know I am
missing something with the annotations but can't quite seam to figure out
what exactly I am missing when I go to get my list of flights.
Thank you,
On Mon, Jun 13, 2011 at 8:41 AM, Arul Dhesiaseelan <aruld_at_acm.org> wrote:
> You could try adding this to Airport class which honors annotations on the
> field.
> @XmlAccessorType(XmlAccessType.FIELD)
>
> Or, move this annotation to the getFlights() method
>
> @XmlElementWrapper(name = "flightList")
> @XmlElement(name = "flight")
>
> -Arul
>
>
> On Mon, Jun 13, 2011 at 9:21 AM, Eric Reagan <reaganej_at_gmail.com> wrote:
>
>> 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
>>
>
>
>
>
--
Eric Reagan