You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by arnavawasthi <ar...@gmail.com> on 2011/04/30 22:15:50 UTC

How to submit JSON data as request body in Apache CXF jax-rs (REST)

I am using Apache-CXF for creating REST web services and trying to submit a
form.

Server:
This is my method, which is expected to get json data.

@POST
@Path("/addCustomer/")
@Consumes(MediaType.APPLICATION_JSON)
//{"Customer":{"name":"Some Name","id":6}}
public Customer addCustomer(Customer customer){
logger.debug(customer);
return customer;
}


Client:
I am using firefox REST plugin for submitting request:
Using REST client, I have posted following json as request body:
{"Customer":{"name":"Arnav Awasthi","id":6}}

But I am getting "415: Unsupported Media Type". --
View this message in context: http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4361669.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to submit JSON data as request body in Apache CXF jax-rs (REST)

Posted by Sergey Beryozkin <sb...@gmail.com>.
That said I fixed it to make sure JSON sequences created from the
explicit collections of beans without a preconfigured wrapper name can
be read as is. It might've been a regression after all - I added a
test now...

Cheers, Sergey

On Tue, May 3, 2011 at 10:50 AM, Sergey Beryozkin <sb...@gmail.com> wrote:
> Hi
>
> Response contains 'Customers' because you have an explicit collection
> of Customer beans returned and Customer bean's xml name is 'Customer'
> - by default JSONProvider will try to pluralize it in order to have a
> 'better' collection name.
>
> When you get an explicit (top-level) JSON collection submitted, it has
> to be 'Customer' - because all we hae on the input is Customer.class
> instance to be populated, thus having 'Customers' won't work.
>
> What you can do is:
> - customize the name of the collection wrapper to 'Customer':
> http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-Handlingexplicitcollections
>
> or set inTransformElements property on JSONProvider:
> http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-CustomizingJAXBXMLandJSONinputandoutput
>
> which will convert 'Customers' into 'Customer' on input:
>
> "Customers" : "Customer"
>
> Hope that helps, Sergey
>
>
>
> On Tue, May 3, 2011 at 10:33 AM, arnavawasthi <ar...@gmail.com> wrote:
>> There was one more issue.
>>
>> List of Customers: Notice the "Customers" root key.
>> http://localhost:8080/cxfjaxrs/jaxrs/customerservice/listCustomers
>> Response:
>> {"Customers":[{"id":2999,"name":"Som Awasthi"},{"id":3000,"name":"Arnav
>> Awasthi"}]}
>>
>> When I submitted the same in addCustomersList
>>
>> http://localhost:8080/cxfjaxrs/jaxrs/customerservice/addCustomersList
>> Response:
>> {"Customers":[JAXBException occurred : unable to marshal type
>> "com.sun.org.apache.xerces.internal.dom.ElementNSImpl" as an element because
>> it is missing an @XmlRootElement annotation. unable to marshal type
>> "com.sun.org.apache.xerces.internal.dom.ElementNSImpl" as an element because
>> it is missing an @XmlRootElement annotation.
>>
>> And when I changed the key from "Customers" to "Customer", it worked. This
>> is somewhat confusing. Ideally same json format should work both ways.
>>
>> Thanks,
>> Arnav
>>
>> On Sun, May 1, 2011 at 10:45 PM, Sergey Beryozkin-5[via CXF] <
>> ml-node+4363121-250164445-204256@n5.nabble.com> wrote:
>>
>>> Please try 2.3.4
>>>
>>> thanks, Sergey
>>>
>>> On Sun, May 1, 2011 at 3:50 PM, arnavawasthi <[hidden email]<http://user/SendEmail.jtp?type=node&node=4363121&i=0&by-user=t>>
>>> wrote:
>>>
>>> > Souce code:
>>> > https://bitbucket.org/arnavawasthi/apache-cxf-jaxrs-spring/overview
>>> >
>>> > Test case:
>>> > I want to add multiple customers in one request. So instead of making
>>> > multiple calls, I want to make one with array of Customer objects. I
>>> > expected that this array would be easily converted into List<Customer>
>>> but
>>> > it didn't work as expected.
>>> >
>>> > URL:
>>> http://localhost:8080/jaxrs/jaxrs/customerservice/addCustomersArray/
>>> > Accept: application/json
>>> > Content-Type: application/json
>>> > Input JSON:
>>> > {"Customers":{"Customer":[{"id":2999,"name":"Som
>>> > Awasthi"},{"id":3000,"name":"Arnav Awasthi"}]}}
>>> >
>>> > Output: ERROR
>>> >
>>> > Accept: application/json
>>> > Content-Type: application/xml
>>> > Input XML:
>>> > <Customers><Customer><id>2999</id><name>Som
>>> > Awasthi</name></Customer><Customer><id>3000</id><name>Arnav
>>> > Awasthi</name></Customer></Customers>
>>> >
>>> > Output json:
>>> > {"Customers":{"Customer":[{"id":2999,"name":"Som
>>> > Awasthi"},{"id":3000,"name":"Arnav Awasthi"}]}}
>>> >
>>> > Now since you have the source code, you can try other options as well.
>>> Let
>>> > me know if you get it working.
>>> >
>>> > Thanks,
>>> > Arnav
>>> >
>>> > On Sun, May 1, 2011 at 7:13 PM, arnav awasthi <[hidden email]<http://user/SendEmail.jtp?type=node&node=4363121&i=1&by-user=t>>wrote:
>>>
>>> >
>>> >> If you want, I can share the code and use cases I am trying.
>>> >>
>>> >> On Sun, May 1, 2011 at 7:12 PM, Benson Margulies[via CXF] <
>>> >> [hidden email]<http://user/SendEmail.jtp?type=node&node=4363121&i=2&by-user=t>>
>>> wrote:
>>> >>
>>> >>> Now we have to wait for Sergey or someone. I'm puzzled by this
>>> >>> producing that particular error status.
>>> >>>
>>> >>> On Sun, May 1, 2011 at 9:39 AM, arnavawasthi <[hidden email]<
>>> http://user/SendEmail.jtp?type=node&node=4362780&i=0&by-user=t>>
>>>
>>> >>> wrote:
>>> >>>
>>> >>> > @Consumes("application/json") was already there. Just to experiment I
>>>
>>> >>> added
>>> >>> > @Consumes({"application/xml", "application/json"}) and tried with
>>> >>> equivalent
>>> >>> > xml instead. With xml it worked.
>>> >>> > Input XML:
>>> >>> > <Customers><Customer><id>2999</id><name>Som
>>> >>> > Awasthi</name></Customer><Customer><id>3000</id><name>Arnav
>>> >>> > Awasthi</name></Customer></Customers>
>>> >>> >
>>> >>> > Output JSON:
>>> >>> > {"Customer":[{"id":2999,"name":"Som
>>> Awasthi"},{"id":3000,"name":"Arnav
>>> >>> > Awasthi"}]}
>>> >>> >
>>> >>> > But if I try the opposite, it doesn't work. May be this error is due
>>> to
>>> >>> the
>>> >>> > JAXB library, which does not support this feature.--
>>> >>> > View this message in context:
>>> >>>
>>> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html<http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html?by-user=t><http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html%3Chttp://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html?by-user=t%3E&by-user=t>
>>>
>>> >>>
>>> >>> > Sent from the cxf-user mailing list archive at Nabble.com.
>>> >>> >
>>> >>>
>>> >>>
>>> >>> ------------------------------
>>> >>>  If you reply to this email, your message will be added to the
>>> discussion
>>> >>> below:
>>> >>>
>>> >>>
>>> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362780.html<http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362780.html?by-user=t>
>>> >>>  To unsubscribe from How to submit JSON data as request body in Apache
>>> CXF
>>> >>> jax-rs (REST), click here<
>>> >>>
>>> >>>
>>> >>
>>> >>
>>> > --
>>> > View this message in context:
>>> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362858.html<http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362858.html?by-user=t>
>>> > Sent from the cxf-user mailing list archive at Nabble.com.
>>>
>>>
>>>
>>> --
>>> Sergey Beryozkin
>>>
>>> Application Integration Division of Talend
>>> http://sberyozkin.blogspot.com
>>>
>>>
>>> ------------------------------
>>>  If you reply to this email, your message will be added to the discussion
>>> below:
>>>
>>> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4363121.html
>>>  To unsubscribe from How to submit JSON data as request body in Apache CXF
>>> jax-rs (REST), click here<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4361669&code=YXJuYXZhd2FzdGhpQGdtYWlsLmNvbXw0MzYxNjY5fC04MTcxNzc0NTY=>.
>>>
>>>
>>
>>
>> --
>> View this message in context: http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4366811.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
>
>
>
> --
> Sergey Beryozkin
>
> Application Integration Division of Talend
> http://sberyozkin.blogspot.com
>



-- 
Sergey Beryozkin

Application Integration Division of Talend
http://sberyozkin.blogspot.com

Re: How to submit JSON data as request body in Apache CXF jax-rs (REST)

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

Response contains 'Customers' because you have an explicit collection
of Customer beans returned and Customer bean's xml name is 'Customer'
- by default JSONProvider will try to pluralize it in order to have a
'better' collection name.

When you get an explicit (top-level) JSON collection submitted, it has
to be 'Customer' - because all we hae on the input is Customer.class
instance to be populated, thus having 'Customers' won't work.

What you can do is:
- customize the name of the collection wrapper to 'Customer':
http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-Handlingexplicitcollections

or set inTransformElements property on JSONProvider:
http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-CustomizingJAXBXMLandJSONinputandoutput

which will convert 'Customers' into 'Customer' on input:

"Customers" : "Customer"

Hope that helps, Sergey



On Tue, May 3, 2011 at 10:33 AM, arnavawasthi <ar...@gmail.com> wrote:
> There was one more issue.
>
> List of Customers: Notice the "Customers" root key.
> http://localhost:8080/cxfjaxrs/jaxrs/customerservice/listCustomers
> Response:
> {"Customers":[{"id":2999,"name":"Som Awasthi"},{"id":3000,"name":"Arnav
> Awasthi"}]}
>
> When I submitted the same in addCustomersList
>
> http://localhost:8080/cxfjaxrs/jaxrs/customerservice/addCustomersList
> Response:
> {"Customers":[JAXBException occurred : unable to marshal type
> "com.sun.org.apache.xerces.internal.dom.ElementNSImpl" as an element because
> it is missing an @XmlRootElement annotation. unable to marshal type
> "com.sun.org.apache.xerces.internal.dom.ElementNSImpl" as an element because
> it is missing an @XmlRootElement annotation.
>
> And when I changed the key from "Customers" to "Customer", it worked. This
> is somewhat confusing. Ideally same json format should work both ways.
>
> Thanks,
> Arnav
>
> On Sun, May 1, 2011 at 10:45 PM, Sergey Beryozkin-5[via CXF] <
> ml-node+4363121-250164445-204256@n5.nabble.com> wrote:
>
>> Please try 2.3.4
>>
>> thanks, Sergey
>>
>> On Sun, May 1, 2011 at 3:50 PM, arnavawasthi <[hidden email]<http://user/SendEmail.jtp?type=node&node=4363121&i=0&by-user=t>>
>> wrote:
>>
>> > Souce code:
>> > https://bitbucket.org/arnavawasthi/apache-cxf-jaxrs-spring/overview
>> >
>> > Test case:
>> > I want to add multiple customers in one request. So instead of making
>> > multiple calls, I want to make one with array of Customer objects. I
>> > expected that this array would be easily converted into List<Customer>
>> but
>> > it didn't work as expected.
>> >
>> > URL:
>> http://localhost:8080/jaxrs/jaxrs/customerservice/addCustomersArray/
>> > Accept: application/json
>> > Content-Type: application/json
>> > Input JSON:
>> > {"Customers":{"Customer":[{"id":2999,"name":"Som
>> > Awasthi"},{"id":3000,"name":"Arnav Awasthi"}]}}
>> >
>> > Output: ERROR
>> >
>> > Accept: application/json
>> > Content-Type: application/xml
>> > Input XML:
>> > <Customers><Customer><id>2999</id><name>Som
>> > Awasthi</name></Customer><Customer><id>3000</id><name>Arnav
>> > Awasthi</name></Customer></Customers>
>> >
>> > Output json:
>> > {"Customers":{"Customer":[{"id":2999,"name":"Som
>> > Awasthi"},{"id":3000,"name":"Arnav Awasthi"}]}}
>> >
>> > Now since you have the source code, you can try other options as well.
>> Let
>> > me know if you get it working.
>> >
>> > Thanks,
>> > Arnav
>> >
>> > On Sun, May 1, 2011 at 7:13 PM, arnav awasthi <[hidden email]<http://user/SendEmail.jtp?type=node&node=4363121&i=1&by-user=t>>wrote:
>>
>> >
>> >> If you want, I can share the code and use cases I am trying.
>> >>
>> >> On Sun, May 1, 2011 at 7:12 PM, Benson Margulies[via CXF] <
>> >> [hidden email]<http://user/SendEmail.jtp?type=node&node=4363121&i=2&by-user=t>>
>> wrote:
>> >>
>> >>> Now we have to wait for Sergey or someone. I'm puzzled by this
>> >>> producing that particular error status.
>> >>>
>> >>> On Sun, May 1, 2011 at 9:39 AM, arnavawasthi <[hidden email]<
>> http://user/SendEmail.jtp?type=node&node=4362780&i=0&by-user=t>>
>>
>> >>> wrote:
>> >>>
>> >>> > @Consumes("application/json") was already there. Just to experiment I
>>
>> >>> added
>> >>> > @Consumes({"application/xml", "application/json"}) and tried with
>> >>> equivalent
>> >>> > xml instead. With xml it worked.
>> >>> > Input XML:
>> >>> > <Customers><Customer><id>2999</id><name>Som
>> >>> > Awasthi</name></Customer><Customer><id>3000</id><name>Arnav
>> >>> > Awasthi</name></Customer></Customers>
>> >>> >
>> >>> > Output JSON:
>> >>> > {"Customer":[{"id":2999,"name":"Som
>> Awasthi"},{"id":3000,"name":"Arnav
>> >>> > Awasthi"}]}
>> >>> >
>> >>> > But if I try the opposite, it doesn't work. May be this error is due
>> to
>> >>> the
>> >>> > JAXB library, which does not support this feature.--
>> >>> > View this message in context:
>> >>>
>> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html<http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html?by-user=t><http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html%3Chttp://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html?by-user=t%3E&by-user=t>
>>
>> >>>
>> >>> > Sent from the cxf-user mailing list archive at Nabble.com.
>> >>> >
>> >>>
>> >>>
>> >>> ------------------------------
>> >>>  If you reply to this email, your message will be added to the
>> discussion
>> >>> below:
>> >>>
>> >>>
>> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362780.html<http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362780.html?by-user=t>
>> >>>  To unsubscribe from How to submit JSON data as request body in Apache
>> CXF
>> >>> jax-rs (REST), click here<
>> >>>
>> >>>
>> >>
>> >>
>> > --
>> > View this message in context:
>> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362858.html<http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362858.html?by-user=t>
>> > Sent from the cxf-user mailing list archive at Nabble.com.
>>
>>
>>
>> --
>> Sergey Beryozkin
>>
>> Application Integration Division of Talend
>> http://sberyozkin.blogspot.com
>>
>>
>> ------------------------------
>>  If you reply to this email, your message will be added to the discussion
>> below:
>>
>> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4363121.html
>>  To unsubscribe from How to submit JSON data as request body in Apache CXF
>> jax-rs (REST), click here<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4361669&code=YXJuYXZhd2FzdGhpQGdtYWlsLmNvbXw0MzYxNjY5fC04MTcxNzc0NTY=>.
>>
>>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4366811.html
> Sent from the cxf-user mailing list archive at Nabble.com.



-- 
Sergey Beryozkin

Application Integration Division of Talend
http://sberyozkin.blogspot.com

Re: How to submit JSON data as request body in Apache CXF jax-rs (REST)

Posted by arnavawasthi <ar...@gmail.com>.
There was one more issue.

List of Customers: Notice the "Customers" root key.
http://localhost:8080/cxfjaxrs/jaxrs/customerservice/listCustomers
Response:
{"Customers":[{"id":2999,"name":"Som Awasthi"},{"id":3000,"name":"Arnav
Awasthi"}]}

When I submitted the same in addCustomersList

http://localhost:8080/cxfjaxrs/jaxrs/customerservice/addCustomersList
Response:
{"Customers":[JAXBException occurred : unable to marshal type
"com.sun.org.apache.xerces.internal.dom.ElementNSImpl" as an element because
it is missing an @XmlRootElement annotation. unable to marshal type
"com.sun.org.apache.xerces.internal.dom.ElementNSImpl" as an element because
it is missing an @XmlRootElement annotation.

And when I changed the key from "Customers" to "Customer", it worked. This
is somewhat confusing. Ideally same json format should work both ways.

Thanks,
Arnav

On Sun, May 1, 2011 at 10:45 PM, Sergey Beryozkin-5[via CXF] <
ml-node+4363121-250164445-204256@n5.nabble.com> wrote:

> Please try 2.3.4
>
> thanks, Sergey
>
> On Sun, May 1, 2011 at 3:50 PM, arnavawasthi <[hidden email]<http://user/SendEmail.jtp?type=node&node=4363121&i=0&by-user=t>>
> wrote:
>
> > Souce code:
> > https://bitbucket.org/arnavawasthi/apache-cxf-jaxrs-spring/overview
> >
> > Test case:
> > I want to add multiple customers in one request. So instead of making
> > multiple calls, I want to make one with array of Customer objects. I
> > expected that this array would be easily converted into List<Customer>
> but
> > it didn't work as expected.
> >
> > URL:
> http://localhost:8080/jaxrs/jaxrs/customerservice/addCustomersArray/
> > Accept: application/json
> > Content-Type: application/json
> > Input JSON:
> > {"Customers":{"Customer":[{"id":2999,"name":"Som
> > Awasthi"},{"id":3000,"name":"Arnav Awasthi"}]}}
> >
> > Output: ERROR
> >
> > Accept: application/json
> > Content-Type: application/xml
> > Input XML:
> > <Customers><Customer><id>2999</id><name>Som
> > Awasthi</name></Customer><Customer><id>3000</id><name>Arnav
> > Awasthi</name></Customer></Customers>
> >
> > Output json:
> > {"Customers":{"Customer":[{"id":2999,"name":"Som
> > Awasthi"},{"id":3000,"name":"Arnav Awasthi"}]}}
> >
> > Now since you have the source code, you can try other options as well.
> Let
> > me know if you get it working.
> >
> > Thanks,
> > Arnav
> >
> > On Sun, May 1, 2011 at 7:13 PM, arnav awasthi <[hidden email]<http://user/SendEmail.jtp?type=node&node=4363121&i=1&by-user=t>>wrote:
>
> >
> >> If you want, I can share the code and use cases I am trying.
> >>
> >> On Sun, May 1, 2011 at 7:12 PM, Benson Margulies[via CXF] <
> >> [hidden email]<http://user/SendEmail.jtp?type=node&node=4363121&i=2&by-user=t>>
> wrote:
> >>
> >>> Now we have to wait for Sergey or someone. I'm puzzled by this
> >>> producing that particular error status.
> >>>
> >>> On Sun, May 1, 2011 at 9:39 AM, arnavawasthi <[hidden email]<
> http://user/SendEmail.jtp?type=node&node=4362780&i=0&by-user=t>>
>
> >>> wrote:
> >>>
> >>> > @Consumes("application/json") was already there. Just to experiment I
>
> >>> added
> >>> > @Consumes({"application/xml", "application/json"}) and tried with
> >>> equivalent
> >>> > xml instead. With xml it worked.
> >>> > Input XML:
> >>> > <Customers><Customer><id>2999</id><name>Som
> >>> > Awasthi</name></Customer><Customer><id>3000</id><name>Arnav
> >>> > Awasthi</name></Customer></Customers>
> >>> >
> >>> > Output JSON:
> >>> > {"Customer":[{"id":2999,"name":"Som
> Awasthi"},{"id":3000,"name":"Arnav
> >>> > Awasthi"}]}
> >>> >
> >>> > But if I try the opposite, it doesn't work. May be this error is due
> to
> >>> the
> >>> > JAXB library, which does not support this feature.--
> >>> > View this message in context:
> >>>
> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html<http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html?by-user=t><http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html%3Chttp://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html?by-user=t%3E&by-user=t>
>
> >>>
> >>> > Sent from the cxf-user mailing list archive at Nabble.com.
> >>> >
> >>>
> >>>
> >>> ------------------------------
> >>>  If you reply to this email, your message will be added to the
> discussion
> >>> below:
> >>>
> >>>
> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362780.html<http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362780.html?by-user=t>
> >>>  To unsubscribe from How to submit JSON data as request body in Apache
> CXF
> >>> jax-rs (REST), click here<
> >>>
> >>>
> >>
> >>
> > --
> > View this message in context:
> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362858.html<http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362858.html?by-user=t>
> > Sent from the cxf-user mailing list archive at Nabble.com.
>
>
>
> --
> Sergey Beryozkin
>
> Application Integration Division of Talend
> http://sberyozkin.blogspot.com
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4363121.html
>  To unsubscribe from How to submit JSON data as request body in Apache CXF
> jax-rs (REST), click here<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4361669&code=YXJuYXZhd2FzdGhpQGdtYWlsLmNvbXw0MzYxNjY5fC04MTcxNzc0NTY=>.
>
>


--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4366811.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to submit JSON data as request body in Apache CXF jax-rs (REST)

Posted by arnavawasthi <ar...@gmail.com>.
Thanks Sergey, your solution works. I have updated the source code [actually
pom.xml :)].

Source code:
https://bitbucket.org/arnavawasthi/apache-cxf-jaxrs-spring

Hopefully that will help others facing the same issue.

Regards,
Arnav

On Sun, May 1, 2011 at 10:45 PM, Sergey Beryozkin-5[via CXF] <
ml-node+4363121-250164445-204256@n5.nabble.com> wrote:

> Please try 2.3.4
>
> thanks, Sergey
>
> On Sun, May 1, 2011 at 3:50 PM, arnavawasthi <[hidden email]<http://user/SendEmail.jtp?type=node&node=4363121&i=0&by-user=t>>
> wrote:
>
> > Souce code:
> > https://bitbucket.org/arnavawasthi/apache-cxf-jaxrs-spring/overview
> >
> > Test case:
> > I want to add multiple customers in one request. So instead of making
> > multiple calls, I want to make one with array of Customer objects. I
> > expected that this array would be easily converted into List<Customer>
> but
> > it didn't work as expected.
> >
> > URL:
> http://localhost:8080/jaxrs/jaxrs/customerservice/addCustomersArray/
> > Accept: application/json
> > Content-Type: application/json
> > Input JSON:
> > {"Customers":{"Customer":[{"id":2999,"name":"Som
> > Awasthi"},{"id":3000,"name":"Arnav Awasthi"}]}}
> >
> > Output: ERROR
> >
> > Accept: application/json
> > Content-Type: application/xml
> > Input XML:
> > <Customers><Customer><id>2999</id><name>Som
> > Awasthi</name></Customer><Customer><id>3000</id><name>Arnav
> > Awasthi</name></Customer></Customers>
> >
> > Output json:
> > {"Customers":{"Customer":[{"id":2999,"name":"Som
> > Awasthi"},{"id":3000,"name":"Arnav Awasthi"}]}}
> >
> > Now since you have the source code, you can try other options as well.
> Let
> > me know if you get it working.
> >
> > Thanks,
> > Arnav
> >
> > On Sun, May 1, 2011 at 7:13 PM, arnav awasthi <[hidden email]<http://user/SendEmail.jtp?type=node&node=4363121&i=1&by-user=t>>wrote:
>
> >
> >> If you want, I can share the code and use cases I am trying.
> >>
> >> On Sun, May 1, 2011 at 7:12 PM, Benson Margulies[via CXF] <
> >> [hidden email]<http://user/SendEmail.jtp?type=node&node=4363121&i=2&by-user=t>>
> wrote:
> >>
> >>> Now we have to wait for Sergey or someone. I'm puzzled by this
> >>> producing that particular error status.
> >>>
> >>> On Sun, May 1, 2011 at 9:39 AM, arnavawasthi <[hidden email]<
> http://user/SendEmail.jtp?type=node&node=4362780&i=0&by-user=t>>
>
> >>> wrote:
> >>>
> >>> > @Consumes("application/json") was already there. Just to experiment I
>
> >>> added
> >>> > @Consumes({"application/xml", "application/json"}) and tried with
> >>> equivalent
> >>> > xml instead. With xml it worked.
> >>> > Input XML:
> >>> > <Customers><Customer><id>2999</id><name>Som
> >>> > Awasthi</name></Customer><Customer><id>3000</id><name>Arnav
> >>> > Awasthi</name></Customer></Customers>
> >>> >
> >>> > Output JSON:
> >>> > {"Customer":[{"id":2999,"name":"Som
> Awasthi"},{"id":3000,"name":"Arnav
> >>> > Awasthi"}]}
> >>> >
> >>> > But if I try the opposite, it doesn't work. May be this error is due
> to
> >>> the
> >>> > JAXB library, which does not support this feature.--
> >>> > View this message in context:
> >>>
> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html<http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html?by-user=t><http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html%3Chttp://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html?by-user=t%3E&by-user=t>
>
> >>>
> >>> > Sent from the cxf-user mailing list archive at Nabble.com.
> >>> >
> >>>
> >>>
> >>> ------------------------------
> >>>  If you reply to this email, your message will be added to the
> discussion
> >>> below:
> >>>
> >>>
> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362780.html<http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362780.html?by-user=t>
> >>>  To unsubscribe from How to submit JSON data as request body in Apache
> CXF
> >>> jax-rs (REST), click here<
> >>>
> >>>
> >>
> >>
> > --
> > View this message in context:
> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362858.html<http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362858.html?by-user=t>
> > Sent from the cxf-user mailing list archive at Nabble.com.
>
>
>
> --
> Sergey Beryozkin
>
> Application Integration Division of Talend
> http://sberyozkin.blogspot.com
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4363121.html
>  To unsubscribe from How to submit JSON data as request body in Apache CXF
> jax-rs (REST), click here<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4361669&code=YXJuYXZhd2FzdGhpQGdtYWlsLmNvbXw0MzYxNjY5fC04MTcxNzc0NTY=>.
>
>
--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4363192.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to submit JSON data as request body in Apache CXF jax-rs (REST)

Posted by Sergey Beryozkin <sb...@gmail.com>.
Please try 2.3.4

thanks, Sergey

On Sun, May 1, 2011 at 3:50 PM, arnavawasthi <ar...@gmail.com> wrote:
> Souce code:
> https://bitbucket.org/arnavawasthi/apache-cxf-jaxrs-spring/overview
>
> Test case:
> I want to add multiple customers in one request. So instead of making
> multiple calls, I want to make one with array of Customer objects. I
> expected that this array would be easily converted into List<Customer> but
> it didn't work as expected.
>
> URL: http://localhost:8080/jaxrs/jaxrs/customerservice/addCustomersArray/
> Accept: application/json
> Content-Type: application/json
> Input JSON:
> {"Customers":{"Customer":[{"id":2999,"name":"Som
> Awasthi"},{"id":3000,"name":"Arnav Awasthi"}]}}
>
> Output: ERROR
>
> Accept: application/json
> Content-Type: application/xml
> Input XML:
> <Customers><Customer><id>2999</id><name>Som
> Awasthi</name></Customer><Customer><id>3000</id><name>Arnav
> Awasthi</name></Customer></Customers>
>
> Output json:
> {"Customers":{"Customer":[{"id":2999,"name":"Som
> Awasthi"},{"id":3000,"name":"Arnav Awasthi"}]}}
>
> Now since you have the source code, you can try other options as well. Let
> me know if you get it working.
>
> Thanks,
> Arnav
>
> On Sun, May 1, 2011 at 7:13 PM, arnav awasthi <ar...@gmail.com>wrote:
>
>> If you want, I can share the code and use cases I am trying.
>>
>> On Sun, May 1, 2011 at 7:12 PM, Benson Margulies[via CXF] <
>> ml-node+4362780-1151034013-204256@n5.nabble.com> wrote:
>>
>>> Now we have to wait for Sergey or someone. I'm puzzled by this
>>> producing that particular error status.
>>>
>>> On Sun, May 1, 2011 at 9:39 AM, arnavawasthi <[hidden email]<http://user/SendEmail.jtp?type=node&node=4362780&i=0&by-user=t>>
>>> wrote:
>>>
>>> > @Consumes("application/json") was already there. Just to experiment I
>>> added
>>> > @Consumes({"application/xml", "application/json"}) and tried with
>>> equivalent
>>> > xml instead. With xml it worked.
>>> > Input XML:
>>> > <Customers><Customer><id>2999</id><name>Som
>>> > Awasthi</name></Customer><Customer><id>3000</id><name>Arnav
>>> > Awasthi</name></Customer></Customers>
>>> >
>>> > Output JSON:
>>> > {"Customer":[{"id":2999,"name":"Som Awasthi"},{"id":3000,"name":"Arnav
>>> > Awasthi"}]}
>>> >
>>> > But if I try the opposite, it doesn't work. May be this error is due to
>>> the
>>> > JAXB library, which does not support this feature.--
>>> > View this message in context:
>>> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html<http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html?by-user=t>
>>>
>>> > Sent from the cxf-user mailing list archive at Nabble.com.
>>> >
>>>
>>>
>>> ------------------------------
>>>  If you reply to this email, your message will be added to the discussion
>>> below:
>>>
>>> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362780.html
>>>  To unsubscribe from How to submit JSON data as request body in Apache CXF
>>> jax-rs (REST), click here<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4361669&code=YXJuYXZhd2FzdGhpQGdtYWlsLmNvbXw0MzYxNjY5fC04MTcxNzc0NTY=>.
>>>
>>>
>>
>>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362858.html
> Sent from the cxf-user mailing list archive at Nabble.com.



-- 
Sergey Beryozkin

Application Integration Division of Talend
http://sberyozkin.blogspot.com

Re: How to submit JSON data as request body in Apache CXF jax-rs (REST)

Posted by arnavawasthi <ar...@gmail.com>.
Souce code:
https://bitbucket.org/arnavawasthi/apache-cxf-jaxrs-spring/overview

Test case:
I want to add multiple customers in one request. So instead of making
multiple calls, I want to make one with array of Customer objects. I
expected that this array would be easily converted into List<Customer> but
it didn't work as expected.

URL: http://localhost:8080/jaxrs/jaxrs/customerservice/addCustomersArray/
Accept: application/json
Content-Type: application/json
Input JSON:
{"Customers":{"Customer":[{"id":2999,"name":"Som
Awasthi"},{"id":3000,"name":"Arnav Awasthi"}]}}

Output: ERROR

Accept: application/json
Content-Type: application/xml
Input XML:
<Customers><Customer><id>2999</id><name>Som
Awasthi</name></Customer><Customer><id>3000</id><name>Arnav
Awasthi</name></Customer></Customers>

Output json:
{"Customers":{"Customer":[{"id":2999,"name":"Som
Awasthi"},{"id":3000,"name":"Arnav Awasthi"}]}}

Now since you have the source code, you can try other options as well. Let
me know if you get it working.

Thanks,
Arnav

On Sun, May 1, 2011 at 7:13 PM, arnav awasthi <ar...@gmail.com>wrote:

> If you want, I can share the code and use cases I am trying.
>
> On Sun, May 1, 2011 at 7:12 PM, Benson Margulies[via CXF] <
> ml-node+4362780-1151034013-204256@n5.nabble.com> wrote:
>
>> Now we have to wait for Sergey or someone. I'm puzzled by this
>> producing that particular error status.
>>
>> On Sun, May 1, 2011 at 9:39 AM, arnavawasthi <[hidden email]<http://user/SendEmail.jtp?type=node&node=4362780&i=0&by-user=t>>
>> wrote:
>>
>> > @Consumes("application/json") was already there. Just to experiment I
>> added
>> > @Consumes({"application/xml", "application/json"}) and tried with
>> equivalent
>> > xml instead. With xml it worked.
>> > Input XML:
>> > <Customers><Customer><id>2999</id><name>Som
>> > Awasthi</name></Customer><Customer><id>3000</id><name>Arnav
>> > Awasthi</name></Customer></Customers>
>> >
>> > Output JSON:
>> > {"Customer":[{"id":2999,"name":"Som Awasthi"},{"id":3000,"name":"Arnav
>> > Awasthi"}]}
>> >
>> > But if I try the opposite, it doesn't work. May be this error is due to
>> the
>> > JAXB library, which does not support this feature.--
>> > View this message in context:
>> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html<http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html?by-user=t>
>>
>> > Sent from the cxf-user mailing list archive at Nabble.com.
>> >
>>
>>
>> ------------------------------
>>  If you reply to this email, your message will be added to the discussion
>> below:
>>
>> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362780.html
>>  To unsubscribe from How to submit JSON data as request body in Apache CXF
>> jax-rs (REST), click here<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4361669&code=YXJuYXZhd2FzdGhpQGdtYWlsLmNvbXw0MzYxNjY5fC04MTcxNzc0NTY=>.
>>
>>
>
>
--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362858.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to submit JSON data as request body in Apache CXF jax-rs (REST)

Posted by arnavawasthi <ar...@gmail.com>.
If you want, I can share the code and use cases I am trying.

On Sun, May 1, 2011 at 7:12 PM, Benson Margulies[via CXF] <
ml-node+4362780-1151034013-204256@n5.nabble.com> wrote:

> Now we have to wait for Sergey or someone. I'm puzzled by this
> producing that particular error status.
>
> On Sun, May 1, 2011 at 9:39 AM, arnavawasthi <[hidden email]<http://user/SendEmail.jtp?type=node&node=4362780&i=0&by-user=t>>
> wrote:
>
> > @Consumes("application/json") was already there. Just to experiment I
> added
> > @Consumes({"application/xml", "application/json"}) and tried with
> equivalent
> > xml instead. With xml it worked.
> > Input XML:
> > <Customers><Customer><id>2999</id><name>Som
> > Awasthi</name></Customer><Customer><id>3000</id><name>Arnav
> > Awasthi</name></Customer></Customers>
> >
> > Output JSON:
> > {"Customer":[{"id":2999,"name":"Som Awasthi"},{"id":3000,"name":"Arnav
> > Awasthi"}]}
> >
> > But if I try the opposite, it doesn't work. May be this error is due to
> the
> > JAXB library, which does not support this feature.--
> > View this message in context:
> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html<http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html?by-user=t>
>
> > Sent from the cxf-user mailing list archive at Nabble.com.
> >
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362780.html
>  To unsubscribe from How to submit JSON data as request body in Apache CXF
> jax-rs (REST), click here<http://cxf.547215.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4361669&code=YXJuYXZhd2FzdGhpQGdtYWlsLmNvbXw0MzYxNjY5fC04MTcxNzc0NTY=>.
>
>
--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362785.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to submit JSON data as request body in Apache CXF jax-rs (REST)

Posted by Benson Margulies <bi...@gmail.com>.
Now we have to wait for Sergey or someone. I'm puzzled by this
producing that particular error status.

On Sun, May 1, 2011 at 9:39 AM, arnavawasthi <ar...@gmail.com> wrote:
> @Consumes("application/json") was already there. Just to experiment I added
> @Consumes({"application/xml", "application/json"}) and tried with equivalent
> xml instead. With xml it worked.
> Input XML:
> <Customers><Customer><id>2999</id><name>Som
> Awasthi</name></Customer><Customer><id>3000</id><name>Arnav
> Awasthi</name></Customer></Customers>
>
> Output JSON:
> {"Customer":[{"id":2999,"name":"Som Awasthi"},{"id":3000,"name":"Arnav
> Awasthi"}]}
>
> But if I try the opposite, it doesn't work. May be this error is due to the
> JAXB library, which does not support this feature.--
> View this message in context: http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

Re: How to submit JSON data as request body in Apache CXF jax-rs (REST)

Posted by arnavawasthi <ar...@gmail.com>.
@Consumes("application/json") was already there. Just to experiment I added
@Consumes({"application/xml", "application/json"}) and tried with equivalent
xml instead. With xml it worked. 
Input XML:
<Customers><Customer><id>2999</id><name>Som
Awasthi</name></Customer><Customer><id>3000</id><name>Arnav
Awasthi</name></Customer></Customers>

Output JSON:
{"Customer":[{"id":2999,"name":"Som Awasthi"},{"id":3000,"name":"Arnav
Awasthi"}]}

But if I try the opposite, it doesn't work. May be this error is due to the
JAXB library, which does not support this feature.--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362777.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to submit JSON data as request body in Apache CXF jax-rs (REST)

Posted by Benson Margulies <bi...@gmail.com>.
Don't you just need another @Consumes on the new function? Or just on
the whole class?

On Sun, May 1, 2011 at 1:01 AM, arnavawasthi <ar...@gmail.com> wrote:
> Thanks, that worked.
>
> But now, if I want to post List of Customers in JSON in the following way:
>
>    @POST
>    @Path("/addCustomers/")
>    @Consumes(MediaType.APPLICATION_JSON)
>    //{"Customer":[{"id":2999,"name":"Som Awasthi"},{"id":3000,"name":"Arnav
> Awasthi"}]}
>    public List<Customer> addCustomers(List<Customer> list){
>        logger.debug(list);
>        return list;
>    }
>
> Request Header:
> Content-Type: application/json
>
> Request Body:
> {"Customer":[{"id":2999,"name":"Som Awasthi"},{"id":3000,"name":"Arnav
> Awasthi"}]}
>
> Again the "415: Unsupported Media Type" error.
>
> Input to this request is same, what I have got in the listCustomers call,
> which is as follows:
>
>    @GET
>    @Path("/listCustomers")
>    public List<Customer> listCustomers(){
>        List<Customer> list = new ArrayList<Customer>();
>        list.add(new Customer("Som Awasthi", 2999L));
>        list.add(new Customer("Arnav Awasthi", 3000L));
>
>        return list;
>    }
>
> Regards,
> Arnav--
> View this message in context: http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362318.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>

Re: How to submit JSON data as request body in Apache CXF jax-rs (REST)

Posted by Sergey Beryozkin <sb...@gmail.com>.
This is because CXF 2.3.0 (and Jettison 1.2) do not support reading
explicit collections/arrays, thus
Jettison provider return false from its isReadable

Please upgrade to 2.3.4 or 2.4.0.

thanks, Sergey

On Sun, May 1, 2011 at 6:01 AM, arnavawasthi <ar...@gmail.com> wrote:
> Thanks, that worked.
>
> But now, if I want to post List of Customers in JSON in the following way:
>
>    @POST
>    @Path("/addCustomers/")
>    @Consumes(MediaType.APPLICATION_JSON)
>    //{"Customer":[{"id":2999,"name":"Som Awasthi"},{"id":3000,"name":"Arnav
> Awasthi"}]}
>    public List<Customer> addCustomers(List<Customer> list){
>        logger.debug(list);
>        return list;
>    }
>
> Request Header:
> Content-Type: application/json
>
> Request Body:
> {"Customer":[{"id":2999,"name":"Som Awasthi"},{"id":3000,"name":"Arnav
> Awasthi"}]}
>
> Again the "415: Unsupported Media Type" error.
>
> Input to this request is same, what I have got in the listCustomers call,
> which is as follows:
>
>    @GET
>    @Path("/listCustomers")
>    public List<Customer> listCustomers(){
>        List<Customer> list = new ArrayList<Customer>();
>        list.add(new Customer("Som Awasthi", 2999L));
>        list.add(new Customer("Arnav Awasthi", 3000L));
>
>        return list;
>    }
>
> Regards,
> Arnav--
> View this message in context: http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362318.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>



-- 
Sergey Beryozkin

Application Integration Division of Talend
http://sberyozkin.blogspot.com

Re: How to submit JSON data as request body in Apache CXF jax-rs (REST)

Posted by arnavawasthi <ar...@gmail.com>.
Thanks, that worked.

But now, if I want to post List of Customers in JSON in the following way:

    @POST
    @Path("/addCustomers/")
    @Consumes(MediaType.APPLICATION_JSON)
    //{"Customer":[{"id":2999,"name":"Som Awasthi"},{"id":3000,"name":"Arnav
Awasthi"}]}
    public List<Customer> addCustomers(List<Customer> list){
    	logger.debug(list);
        return list;
    }

Request Header:
Content-Type: application/json

Request Body:
{"Customer":[{"id":2999,"name":"Som Awasthi"},{"id":3000,"name":"Arnav
Awasthi"}]}

Again the "415: Unsupported Media Type" error.

Input to this request is same, what I have got in the listCustomers call,
which is as follows:

    @GET
    @Path("/listCustomers")
    public List<Customer> listCustomers(){
    	List<Customer> list = new ArrayList<Customer>();
    	list.add(new Customer("Som Awasthi", 2999L));
    	list.add(new Customer("Arnav Awasthi", 3000L));
    	
    	return list;
    }

Regards,
Arnav--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4362318.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: How to submit JSON data as request body in Apache CXF jax-rs (REST)

Posted by Benson Margulies <bi...@gmail.com>.
You need to tell the firefox plugin to set the content type.

On Sat, Apr 30, 2011 at 4:15 PM, arnavawasthi <ar...@gmail.com> wrote:
> I am using Apache-CXF for creating REST web services and trying to submit a
> form.
>
> Server:
> This is my method, which is expected to get json data.
>
> @POST
> @Path("/addCustomer/")
> @Consumes(MediaType.APPLICATION_JSON)
> //{"Customer":{"name":"Some Name","id":6}}
> public Customer addCustomer(Customer customer){
> logger.debug(customer);
> return customer;
> }
>
>
> Client:
> I am using firefox REST plugin for submitting request:
> Using REST client, I have posted following json as request body:
> {"Customer":{"name":"Arnav Awasthi","id":6}}
>
> But I am getting "415: Unsupported Media Type". --
> View this message in context: http://cxf.547215.n5.nabble.com/How-to-submit-JSON-data-as-request-body-in-Apache-CXF-jax-rs-REST-tp4361669p4361669.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>