users@jersey.java.net

Re: [Jersey] Jersey client and collection resources

From: Arul Dhesiaseelan <arul_at_fluxcorp.com>
Date: Thu, 23 Oct 2008 17:11:33 -0600

Aaron Bruegl wrote:
> How can I use the Jersey client api to get a Collection? For example
> how would you do a get of the example
> jersey-samples-1.0/jaxb/collection/XmlRootElement?
>
You can find the below test case distributed with the sample which uses
Jersey client to get the collection from JAXBCollectionResource.

    public void testRootElementCollection() {
        GenericType<Collection<JAXBXmlRootElement>> genericType = new
GenericType<Collection<JAXBXmlRootElement>>() {};
        Collection<JAXBXmlRootElement> ce1 =
r.path("jaxb/collection/XmlRootElement").get(genericType);
        Collection<JAXBXmlRootElement> ce2 =
r.path("jaxb/collection/XmlRootElement").type("application/xml").post(genericType,
new GenericEntity<Collection<JAXBXmlRootElement>>(ce1){});
        assertEquals(ce1, ce2);
    }

HTH,
-Arul