You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Gabo Manuel <km...@solegysystems.com> on 2009/08/07 07:28:07 UTC

Re: Handling Collection returns via JAX-RS

Hi Sergey,

> By default, pluralized XMLRootElement name attribute will be used as a
> wrapper, namespace-prefixed if needed, if no name attribute is there then a
> lower-case pluralized class name will be used. 
Just tested the latest release 2.2.3. The rest services handle the 
collections. Just a comment though, I think it would be better to use 
'ArrayOf_<XMLRootElement name attribute>'. It just looks weird to have a 
tag like 'Historys' or 'Datums' (along with other words that have 
special case of plurality) or maybe adding an attribute to the 
annotation to specify the plural term to be used.

Gabo


RE: Handling Collection returns via JAX-RS

Posted by Sergey Beryozkin <se...@iona.com>.
Hi Kiran

Yes, it is only JSONProvider that can not *read* explicit collections like
List<Customer> so Customers wrapper would be needed.
With JAXB it should work, please see

http://svn.apache.org/repos/asf/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

testGetBookCollection()
testGetBookArray()
 
base Collection and Sets are also supported

I'll also add the test using WebClients

cheers, Sergey


kiran.sidhu wrote:
> 
> Hi Sergey,
>                Yes, I meant using CXF JAX-RS Client API.
> I was wondering if JAXB can read the xml in the response and generate
> the collection of Customer objects.
> 
> Thanks
> Kiran
> 
> -----Original Message-----
> From: users-return-16671-kiran.sidhu=asipay.com@cxf.apache.org
> [mailto:users-return-16671-kiran.sidhu=asipay.com@cxf.apache.org] 
> Sent: Tuesday, August 11, 2009 3:41 AM
> To: users@cxf.apache.org
> Subject: RE: Handling Collection<JAXBElement> returns via JAX-RS
> 
> 
> Hi
> 
> Do you mean 'using CXF JAXRS client API' ?
> At the moment explicit collections can not be read by JSONProvider
> (Jettison) - I will look into it; otherwise, Sam's message explains how
> collections can be serialized and then read manually by some JSON-aware
> utils. If it is an option and in case you did refer to a client api then
> you
> may be able to do it like this :
> 
> WebClient client = WebClient.create(address);
> InputStream is = client.get(InputStream.class);
> // read JSON collection
> 
> but as I said, we may be able get it fixed
> 
> 
> cheers, Sergey 
> 
> 
> kiran.sidhu wrote:
>> 
>> Has anybody tried getting the collection out from the Response on the
>> client side ?
>> 
>> -----Original Message-----
>> From: users-return-16606-kiran.sidhu=asipay.com@cxf.apache.org
>> [mailto:users-return-16606-kiran.sidhu=asipay.com@cxf.apache.org] 
>> Sent: Friday, August 07, 2009 12:28 AM
>> To: users@cxf.apache.org; users@cxf.apache.org
>> Subject: RE: Handling Collection<JAXBElement> returns via JAX-RS
>> 
>> Hi Gabo
>> 
>> Yeah, I agree, in some cases names like 'Historys' do no look right
> :-)
>> but it can be tricky to come with the universally acceptable
> collection
>> name, as CXF supports now explicit arrays, lists, base collections and
>> sets. 
>> One can override it by setting a global 'collectionWrapperName' or
>> 'collectionWrapperMap' property on
>> a JAXBElementProvider bean. 'collectionWrapperMap' is a map property,
>> keys are collectionWrapperNames and values are class names, or ex, if
> a
>> given service returns History and Datum then one would use this
>> property.
>> 
>> CollectionWrapperName can be a simple name like 'ListOfHistory' or an
>> expanded QName like
>> '{http://history}ListOfHistory'. In the latter case a 'ns1' prefix
> will
>> be bound to an {http://history} namespace. 
>> 
>> By the way, I've been working on updating the JAX-RS docs for the last
> 2
>> days, so it's all documented now :
>> 
>>
> http://cwiki.apache.org/CXF20DOC/jax-rs.html#JAX-RS-Handlingexplicitcoll
>> ections
>> 
>> but I'm going to spend more time on improving the docs.
>> 
>> thanks, Sergey
>> 
>> -----Original Message-----
>> From: Gabo Manuel [mailto:kmanuel@solegysystems.com]
>> Sent: Fri 8/7/2009 1:28 AM
>> To: users@cxf.apache.org
>> Subject: Re: Handling Collection<JAXBElement> returns via JAX-RS
>>  
>> Hi Sergey,
>> 
>>> By default, pluralized XMLRootElement name attribute will be used as
> a
>>> wrapper, namespace-prefixed if needed, if no name attribute is there
>> then a
>>> lower-case pluralized class name will be used. 
>> Just tested the latest release 2.2.3. The rest services handle the 
>> collections. Just a comment though, I think it would be better to use 
>> 'ArrayOf_<XMLRootElement name attribute>'. It just looks weird to have
> a
>> 
>> tag like 'Historys' or 'Datums' (along with other words that have 
>> special case of plurality) or maybe adding an attribute to the 
>> annotation to specify the plural term to be used.
>> 
>> Gabo
>> 
>> 
>> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> _ _
>> _
>> 
>> Notice: This information is intended only for the person(s) or
> entity(ies)
>> to which it is addressed. This information may contain information
> that is
>> confidential or otherwise protected from disclosure. If you are not
> the
>> intended recipient of this message, or if this message has been
> addressed
>> to you in error, please immediately alert the sender by reply e-mail
> and
>> then delete this message, including any attachments. Any
> dissemination,
>> distribution or other use of the contents of this message by anyone
> other
>> than the intended recipient is strictly prohibited.
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/Handling-Collection%3CJAXBElement%3E-returns-via-J
> AX-RS-tp24262522p24915229.html
> Sent from the cxf-user mailing list archive at Nabble.com.
> 
> 
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> _
> 
> Notice: This information is intended only for the person(s) or entity(ies)
> to which it is addressed. This information may contain information that is
> confidential or otherwise protected from disclosure. If you are not the
> intended recipient of this message, or if this message has been addressed
> to you in error, please immediately alert the sender by reply e-mail and
> then delete this message, including any attachments. Any dissemination,
> distribution or other use of the contents of this message by anyone other
> than the intended recipient is strictly prohibited.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Handling-Collection%3CJAXBElement%3E-returns-via-JAX-RS-tp24262522p24931544.html
Sent from the cxf-user mailing list archive at Nabble.com.


RE: Handling Collection returns via JAX-RS

Posted by ki...@asipay.com.
Hi Sergey,
               Yes, I meant using CXF JAX-RS Client API.
I was wondering if JAXB can read the xml in the response and generate
the collection of Customer objects.

Thanks
Kiran

-----Original Message-----
From: users-return-16671-kiran.sidhu=asipay.com@cxf.apache.org
[mailto:users-return-16671-kiran.sidhu=asipay.com@cxf.apache.org] 
Sent: Tuesday, August 11, 2009 3:41 AM
To: users@cxf.apache.org
Subject: RE: Handling Collection<JAXBElement> returns via JAX-RS


Hi

Do you mean 'using CXF JAXRS client API' ?
At the moment explicit collections can not be read by JSONProvider
(Jettison) - I will look into it; otherwise, Sam's message explains how
collections can be serialized and then read manually by some JSON-aware
utils. If it is an option and in case you did refer to a client api then
you
may be able to do it like this :

WebClient client = WebClient.create(address);
InputStream is = client.get(InputStream.class);
// read JSON collection

but as I said, we may be able get it fixed


cheers, Sergey 


kiran.sidhu wrote:
> 
> Has anybody tried getting the collection out from the Response on the
> client side ?
> 
> -----Original Message-----
> From: users-return-16606-kiran.sidhu=asipay.com@cxf.apache.org
> [mailto:users-return-16606-kiran.sidhu=asipay.com@cxf.apache.org] 
> Sent: Friday, August 07, 2009 12:28 AM
> To: users@cxf.apache.org; users@cxf.apache.org
> Subject: RE: Handling Collection<JAXBElement> returns via JAX-RS
> 
> Hi Gabo
> 
> Yeah, I agree, in some cases names like 'Historys' do no look right
:-)
> but it can be tricky to come with the universally acceptable
collection
> name, as CXF supports now explicit arrays, lists, base collections and
> sets. 
> One can override it by setting a global 'collectionWrapperName' or
> 'collectionWrapperMap' property on
> a JAXBElementProvider bean. 'collectionWrapperMap' is a map property,
> keys are collectionWrapperNames and values are class names, or ex, if
a
> given service returns History and Datum then one would use this
> property.
> 
> CollectionWrapperName can be a simple name like 'ListOfHistory' or an
> expanded QName like
> '{http://history}ListOfHistory'. In the latter case a 'ns1' prefix
will
> be bound to an {http://history} namespace. 
> 
> By the way, I've been working on updating the JAX-RS docs for the last
2
> days, so it's all documented now :
> 
>
http://cwiki.apache.org/CXF20DOC/jax-rs.html#JAX-RS-Handlingexplicitcoll
> ections
> 
> but I'm going to spend more time on improving the docs.
> 
> thanks, Sergey
> 
> -----Original Message-----
> From: Gabo Manuel [mailto:kmanuel@solegysystems.com]
> Sent: Fri 8/7/2009 1:28 AM
> To: users@cxf.apache.org
> Subject: Re: Handling Collection<JAXBElement> returns via JAX-RS
>  
> Hi Sergey,
> 
>> By default, pluralized XMLRootElement name attribute will be used as
a
>> wrapper, namespace-prefixed if needed, if no name attribute is there
> then a
>> lower-case pluralized class name will be used. 
> Just tested the latest release 2.2.3. The rest services handle the 
> collections. Just a comment though, I think it would be better to use 
> 'ArrayOf_<XMLRootElement name attribute>'. It just looks weird to have
a
> 
> tag like 'Historys' or 'Datums' (along with other words that have 
> special case of plurality) or maybe adding an attribute to the 
> annotation to specify the plural term to be used.
> 
> Gabo
> 
> 
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
_ _
> _
> 
> Notice: This information is intended only for the person(s) or
entity(ies)
> to which it is addressed. This information may contain information
that is
> confidential or otherwise protected from disclosure. If you are not
the
> intended recipient of this message, or if this message has been
addressed
> to you in error, please immediately alert the sender by reply e-mail
and
> then delete this message, including any attachments. Any
dissemination,
> distribution or other use of the contents of this message by anyone
other
> than the intended recipient is strictly prohibited.
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/Handling-Collection%3CJAXBElement%3E-returns-via-J
AX-RS-tp24262522p24915229.html
Sent from the cxf-user mailing list archive at Nabble.com.


_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Notice: This information is intended only for the person(s) or entity(ies) to which it is addressed. This information may contain information that is confidential or otherwise protected from disclosure. If you are not the intended recipient of this message, or if this message has been addressed to you in error, please immediately alert the sender by reply e-mail and then delete this message, including any attachments. Any dissemination, distribution or other use of the contents of this message by anyone other than the intended recipient is strictly prohibited.


RE: Handling Collection returns via JAX-RS

Posted by Sergey Beryozkin <se...@iona.com>.
Hi

Do you mean 'using CXF JAXRS client API' ?
At the moment explicit collections can not be read by JSONProvider
(Jettison) - I will look into it; otherwise, Sam's message explains how
collections can be serialized and then read manually by some JSON-aware
utils. If it is an option and in case you did refer to a client api then you
may be able to do it like this :

WebClient client = WebClient.create(address);
InputStream is = client.get(InputStream.class);
// read JSON collection

but as I said, we may be able get it fixed


cheers, Sergey 


kiran.sidhu wrote:
> 
> Has anybody tried getting the collection out from the Response on the
> client side ?
> 
> -----Original Message-----
> From: users-return-16606-kiran.sidhu=asipay.com@cxf.apache.org
> [mailto:users-return-16606-kiran.sidhu=asipay.com@cxf.apache.org] 
> Sent: Friday, August 07, 2009 12:28 AM
> To: users@cxf.apache.org; users@cxf.apache.org
> Subject: RE: Handling Collection<JAXBElement> returns via JAX-RS
> 
> Hi Gabo
> 
> Yeah, I agree, in some cases names like 'Historys' do no look right :-)
> but it can be tricky to come with the universally acceptable collection
> name, as CXF supports now explicit arrays, lists, base collections and
> sets. 
> One can override it by setting a global 'collectionWrapperName' or
> 'collectionWrapperMap' property on
> a JAXBElementProvider bean. 'collectionWrapperMap' is a map property,
> keys are collectionWrapperNames and values are class names, or ex, if a
> given service returns History and Datum then one would use this
> property.
> 
> CollectionWrapperName can be a simple name like 'ListOfHistory' or an
> expanded QName like
> '{http://history}ListOfHistory'. In the latter case a 'ns1' prefix will
> be bound to an {http://history} namespace. 
> 
> By the way, I've been working on updating the JAX-RS docs for the last 2
> days, so it's all documented now :
> 
> http://cwiki.apache.org/CXF20DOC/jax-rs.html#JAX-RS-Handlingexplicitcoll
> ections
> 
> but I'm going to spend more time on improving the docs.
> 
> thanks, Sergey
> 
> -----Original Message-----
> From: Gabo Manuel [mailto:kmanuel@solegysystems.com]
> Sent: Fri 8/7/2009 1:28 AM
> To: users@cxf.apache.org
> Subject: Re: Handling Collection<JAXBElement> returns via JAX-RS
>  
> Hi Sergey,
> 
>> By default, pluralized XMLRootElement name attribute will be used as a
>> wrapper, namespace-prefixed if needed, if no name attribute is there
> then a
>> lower-case pluralized class name will be used. 
> Just tested the latest release 2.2.3. The rest services handle the 
> collections. Just a comment though, I think it would be better to use 
> 'ArrayOf_<XMLRootElement name attribute>'. It just looks weird to have a
> 
> tag like 'Historys' or 'Datums' (along with other words that have 
> special case of plurality) or maybe adding an attribute to the 
> annotation to specify the plural term to be used.
> 
> Gabo
> 
> 
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> _
> 
> Notice: This information is intended only for the person(s) or entity(ies)
> to which it is addressed. This information may contain information that is
> confidential or otherwise protected from disclosure. If you are not the
> intended recipient of this message, or if this message has been addressed
> to you in error, please immediately alert the sender by reply e-mail and
> then delete this message, including any attachments. Any dissemination,
> distribution or other use of the contents of this message by anyone other
> than the intended recipient is strictly prohibited.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Handling-Collection%3CJAXBElement%3E-returns-via-JAX-RS-tp24262522p24915229.html
Sent from the cxf-user mailing list archive at Nabble.com.


RE: Handling Collection returns via JAX-RS

Posted by "Sam.Wang" <Bi...@ge.com>.
Hi Kiran:

I have test version2.2.3, it supports outputting collection now.

following is a demo code:

	@GET
	@Path("/customers/")
	public List<Customer> getCustomers() {
		List<Customer> list = new ArrayList<Customer>();
		Customer c = new Customer();

		c.setName("John1");
		c.setId(123);
		list.add(c);

		c.setName("John2");
		c.setId(234);
		list.add(c);
		Customers cs = new Customers();
		cs.setCustomer(list);
		return list;
	}

So I use the Ajax request to get the response and it will be:

{"Customer":[{"id":234,"name":"John2"},{"id":234,"name":"John2"}]}


kiran.sidhu wrote:
> 
> Has anybody tried getting the collection out from the Response on the
> client side ?
> 
> -----Original Message-----
> ...
> 

-- 
View this message in context: http://www.nabble.com/Handling-Collection%3CJAXBElement%3E-returns-via-JAX-RS-tp24262522p24910154.html
Sent from the cxf-user mailing list archive at Nabble.com.


RE: Handling Collection returns via JAX-RS

Posted by ki...@asipay.com.
Has anybody tried getting the collection out from the Response on the
client side ?

-----Original Message-----
From: users-return-16606-kiran.sidhu=asipay.com@cxf.apache.org
[mailto:users-return-16606-kiran.sidhu=asipay.com@cxf.apache.org] 
Sent: Friday, August 07, 2009 12:28 AM
To: users@cxf.apache.org; users@cxf.apache.org
Subject: RE: Handling Collection<JAXBElement> returns via JAX-RS

Hi Gabo

Yeah, I agree, in some cases names like 'Historys' do no look right :-)
but it can be tricky to come with the universally acceptable collection
name, as CXF supports now explicit arrays, lists, base collections and
sets. 
One can override it by setting a global 'collectionWrapperName' or
'collectionWrapperMap' property on
a JAXBElementProvider bean. 'collectionWrapperMap' is a map property,
keys are collectionWrapperNames and values are class names, or ex, if a
given service returns History and Datum then one would use this
property.

CollectionWrapperName can be a simple name like 'ListOfHistory' or an
expanded QName like
'{http://history}ListOfHistory'. In the latter case a 'ns1' prefix will
be bound to an {http://history} namespace. 

By the way, I've been working on updating the JAX-RS docs for the last 2
days, so it's all documented now :

http://cwiki.apache.org/CXF20DOC/jax-rs.html#JAX-RS-Handlingexplicitcoll
ections

but I'm going to spend more time on improving the docs.

thanks, Sergey

-----Original Message-----
From: Gabo Manuel [mailto:kmanuel@solegysystems.com]
Sent: Fri 8/7/2009 1:28 AM
To: users@cxf.apache.org
Subject: Re: Handling Collection<JAXBElement> returns via JAX-RS
 
Hi Sergey,

> By default, pluralized XMLRootElement name attribute will be used as a
> wrapper, namespace-prefixed if needed, if no name attribute is there
then a
> lower-case pluralized class name will be used. 
Just tested the latest release 2.2.3. The rest services handle the 
collections. Just a comment though, I think it would be better to use 
'ArrayOf_<XMLRootElement name attribute>'. It just looks weird to have a

tag like 'Historys' or 'Datums' (along with other words that have 
special case of plurality) or maybe adding an attribute to the 
annotation to specify the plural term to be used.

Gabo


_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Notice: This information is intended only for the person(s) or entity(ies) to which it is addressed. This information may contain information that is confidential or otherwise protected from disclosure. If you are not the intended recipient of this message, or if this message has been addressed to you in error, please immediately alert the sender by reply e-mail and then delete this message, including any attachments. Any dissemination, distribution or other use of the contents of this message by anyone other than the intended recipient is strictly prohibited.


RE: Handling Collection returns via JAX-RS

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi Gabo

Yeah, I agree, in some cases names like 'Historys' do no look right :-) but it can be tricky to come with the universally acceptable collection name, as CXF supports now explicit arrays, lists, base collections and sets. 
One can override it by setting a global 'collectionWrapperName' or 'collectionWrapperMap' property on
a JAXBElementProvider bean. 'collectionWrapperMap' is a map property, keys are collectionWrapperNames and values are class names, or ex, if a given service returns History and Datum then one would use this property.

CollectionWrapperName can be a simple name like 'ListOfHistory' or an expanded QName like
'{http://history}ListOfHistory'. In the latter case a 'ns1' prefix will be bound to an {http://history} namespace. 

By the way, I've been working on updating the JAX-RS docs for the last 2 days, so it's all documented now :

http://cwiki.apache.org/CXF20DOC/jax-rs.html#JAX-RS-Handlingexplicitcollections

but I'm going to spend more time on improving the docs.

thanks, Sergey

-----Original Message-----
From: Gabo Manuel [mailto:kmanuel@solegysystems.com]
Sent: Fri 8/7/2009 1:28 AM
To: users@cxf.apache.org
Subject: Re: Handling Collection<JAXBElement> returns via JAX-RS
 
Hi Sergey,

> By default, pluralized XMLRootElement name attribute will be used as a
> wrapper, namespace-prefixed if needed, if no name attribute is there then a
> lower-case pluralized class name will be used. 
Just tested the latest release 2.2.3. The rest services handle the 
collections. Just a comment though, I think it would be better to use 
'ArrayOf_<XMLRootElement name attribute>'. It just looks weird to have a 
tag like 'Historys' or 'Datums' (along with other words that have 
special case of plurality) or maybe adding an attribute to the 
annotation to specify the plural term to be used.

Gabo