You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Balaji Sankar Chopparapu <ba...@gmail.com> on 2009/12/22 14:43:05 UTC
problem while posting JSON text to RESTService
Hi All,
I have problem while posting JSON text to RESTService. The service is
failing with Exception
JAXBException occurred : unexpected element (uri:"
http://www.w3.org/2001/XMLSchema-instance", local:"Customer"). Expected
elements are <{}Customer>. unexpected element (uri:"
http://www.w3.org/2001/XMLSchema-instance", local:"Customer"). Expected
elements are <{}Customer>.
I believe this the problem with namespace. Pleas suggest me a solution
JSON Text
-----------------
{"Customer":{"id":123,"name":"Balaji"}}
Customer Service
------------------
@Path("/customerservice/")
public class CustomerService {
@POST
@Path("/customers/")
public Response addCustomer(Customer customer) {
System.out.println("----invoking addCustomer, Customer name is: " +
customer.getName());
customer.setId(++currentId);
customers.put(customer.getId(), customer);
return Response.ok(customer).build();
}
}
Spring-config.xml
--------------
<util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
<entry key="http://www.w3.org/2001/XMLSchema-instance" value=""/>
</util:map>
<jaxrs:serviceBeans>
<ref bean="customerService"/>
</jaxrs:serviceBeans>
Thanks
Balaji
Re: problem while posting JSON text to RESTService
Posted by Balaji Sankar Chopparapu <ba...@gmail.com>.
Thanks Sergey,
Please see below
On Wed, Dec 23, 2009 at 5:36 PM, Sergey Beryozkin <sb...@progress.com>wrote:
> Hi Balaji
>
>
> Thanks Sergey.
>>
>> This solved the problem. I believe property "writeXsiType" is added in
>> 2.2.5
>> Release.
>>
>
> Probably yes. You really need to use it only if you do nnot want the type
> info go on the wire in cases when say a Customer class is returned in the
> signature but some subclass instance like SuperCustomer is actually returned
> at runtime.
[Balaji] Currently we don't have such need.
> Otherwise just do not even specify this property
>
>
>
>> Merry Christmas and a Happy New Year.
>>
>
> Merry Christmas and a Happy New Year to you and indeed to all CXF users and
> developers !
>
> thanks, Sergey
>
>
>
>> Best Regards
>> Balaji
>>
>>
>> On Tue, Dec 22, 2009 at 8:57 PM, Sergey Beryozkin <sberyozk@progress.com
>> >wrote:
>>
>> Hi
>>>
>>> I think this entry is confusing Jettison on the read side :
>>>
>>>
>>> <entry key="http://www.w3.org/2001/XMLSchema-instance" value=""/>
>>>
>>>>
>>>>
>>> and you probably do not need it on the write side either, instead, just
>>> set
>>> a boolean "writeXsiType"
>>> to false if you do not need the hierarchy info to go on the wire
>>>
>>> let us know please if it helps
>>> Cheers, Sergey
>>>
>>>
>>> Hi All,
>>>
>>>>
>>>>
>>>>
>>>> I have problem while posting JSON text to RESTService. The service is
>>>> failing with Exception
>>>>
>>>> JAXBException occurred : unexpected element (uri:"
>>>> http://www.w3.org/2001/XMLSchema-instance", local:"Customer"). Expected
>>>> elements are <{}Customer>. unexpected element (uri:"
>>>> http://www.w3.org/2001/XMLSchema-instance", local:"Customer"). Expected
>>>> elements are <{}Customer>.
>>>>
>>>> I believe this the problem with namespace. Pleas suggest me a solution
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> JSON Text
>>>>
>>>> -----------------
>>>>
>>>> {"Customer":{"id":123,"name":"Balaji"}}
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Customer Service
>>>>
>>>> ------------------
>>>>
>>>> @Path("/customerservice/")
>>>>
>>>> public class CustomerService {
>>>>
>>>> @POST
>>>>
>>>> @Path("/customers/")
>>>>
>>>> public Response addCustomer(Customer customer) {
>>>>
>>>> System.out.println("----invoking addCustomer, Customer name is: " +
>>>> customer.getName());
>>>>
>>>> customer.setId(++currentId);
>>>>
>>>>
>>>>
>>>> customers.put(customer.getId(), customer);
>>>>
>>>>
>>>>
>>>> return Response.ok(customer).build();
>>>>
>>>> }
>>>>
>>>> }
>>>>
>>>>
>>>>
>>>> Spring-config.xml
>>>>
>>>> --------------
>>>>
>>>> <util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
>>>>
>>>> <entry key="http://www.w3.org/2001/XMLSchema-instance" value=""/>
>>>>
>>>> </util:map>
>>>>
>>>>
>>>>
>>>> <jaxrs:serviceBeans>
>>>>
>>>> <ref bean="customerService"/>
>>>>
>>>> </jaxrs:serviceBeans>
>>>>
>>>>
>>>> Thanks
>>>>
>>>> Balaji
>>>>
>>>>
>>>>
>>
>
Re: problem while posting JSON text to RESTService
Posted by Sergey Beryozkin <sb...@progress.com>.
Hi Balaji
> Thanks Sergey.
>
> This solved the problem. I believe property "writeXsiType" is added in 2.2.5
> Release.
Probably yes. You really need to use it only if you do nnot want the type info go on the wire in cases when say a Customer class is
returned in the signature but some subclass instance like SuperCustomer is actually returned at runtime. Otherwise just do not even
specify this property
>
> Merry Christmas and a Happy New Year.
Merry Christmas and a Happy New Year to you and indeed to all CXF users and developers !
thanks, Sergey
>
> Best Regards
> Balaji
>
>
> On Tue, Dec 22, 2009 at 8:57 PM, Sergey Beryozkin <sb...@progress.com>wrote:
>
>> Hi
>>
>> I think this entry is confusing Jettison on the read side :
>>
>>
>> <entry key="http://www.w3.org/2001/XMLSchema-instance" value=""/>
>>>
>>
>> and you probably do not need it on the write side either, instead, just set
>> a boolean "writeXsiType"
>> to false if you do not need the hierarchy info to go on the wire
>>
>> let us know please if it helps
>> Cheers, Sergey
>>
>>
>> Hi All,
>>>
>>>
>>>
>>> I have problem while posting JSON text to RESTService. The service is
>>> failing with Exception
>>>
>>> JAXBException occurred : unexpected element (uri:"
>>> http://www.w3.org/2001/XMLSchema-instance", local:"Customer"). Expected
>>> elements are <{}Customer>. unexpected element (uri:"
>>> http://www.w3.org/2001/XMLSchema-instance", local:"Customer"). Expected
>>> elements are <{}Customer>.
>>>
>>> I believe this the problem with namespace. Pleas suggest me a solution
>>>
>>>
>>>
>>>
>>>
>>> JSON Text
>>>
>>> -----------------
>>>
>>> {"Customer":{"id":123,"name":"Balaji"}}
>>>
>>>
>>>
>>>
>>>
>>> Customer Service
>>>
>>> ------------------
>>>
>>> @Path("/customerservice/")
>>>
>>> public class CustomerService {
>>>
>>> @POST
>>>
>>> @Path("/customers/")
>>>
>>> public Response addCustomer(Customer customer) {
>>>
>>> System.out.println("----invoking addCustomer, Customer name is: " +
>>> customer.getName());
>>>
>>> customer.setId(++currentId);
>>>
>>>
>>>
>>> customers.put(customer.getId(), customer);
>>>
>>>
>>>
>>> return Response.ok(customer).build();
>>>
>>> }
>>>
>>> }
>>>
>>>
>>>
>>> Spring-config.xml
>>>
>>> --------------
>>>
>>> <util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
>>>
>>> <entry key="http://www.w3.org/2001/XMLSchema-instance" value=""/>
>>>
>>> </util:map>
>>>
>>>
>>>
>>> <jaxrs:serviceBeans>
>>>
>>> <ref bean="customerService"/>
>>>
>>> </jaxrs:serviceBeans>
>>>
>>>
>>> Thanks
>>>
>>> Balaji
>>>
>>>
>
Re: problem while posting JSON text to RESTService
Posted by Balaji Sankar Chopparapu <ba...@gmail.com>.
Thanks Sergey.
This solved the problem. I believe property "writeXsiType" is added in 2.2.5
Release.
Merry Christmas and a Happy New Year.
Best Regards
Balaji
On Tue, Dec 22, 2009 at 8:57 PM, Sergey Beryozkin <sb...@progress.com>wrote:
> Hi
>
> I think this entry is confusing Jettison on the read side :
>
>
> <entry key="http://www.w3.org/2001/XMLSchema-instance" value=""/>
>>
>
> and you probably do not need it on the write side either, instead, just set
> a boolean "writeXsiType"
> to false if you do not need the hierarchy info to go on the wire
>
> let us know please if it helps
> Cheers, Sergey
>
>
> Hi All,
>>
>>
>>
>> I have problem while posting JSON text to RESTService. The service is
>> failing with Exception
>>
>> JAXBException occurred : unexpected element (uri:"
>> http://www.w3.org/2001/XMLSchema-instance", local:"Customer"). Expected
>> elements are <{}Customer>. unexpected element (uri:"
>> http://www.w3.org/2001/XMLSchema-instance", local:"Customer"). Expected
>> elements are <{}Customer>.
>>
>> I believe this the problem with namespace. Pleas suggest me a solution
>>
>>
>>
>>
>>
>> JSON Text
>>
>> -----------------
>>
>> {"Customer":{"id":123,"name":"Balaji"}}
>>
>>
>>
>>
>>
>> Customer Service
>>
>> ------------------
>>
>> @Path("/customerservice/")
>>
>> public class CustomerService {
>>
>> @POST
>>
>> @Path("/customers/")
>>
>> public Response addCustomer(Customer customer) {
>>
>> System.out.println("----invoking addCustomer, Customer name is: " +
>> customer.getName());
>>
>> customer.setId(++currentId);
>>
>>
>>
>> customers.put(customer.getId(), customer);
>>
>>
>>
>> return Response.ok(customer).build();
>>
>> }
>>
>> }
>>
>>
>>
>> Spring-config.xml
>>
>> --------------
>>
>> <util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
>>
>> <entry key="http://www.w3.org/2001/XMLSchema-instance" value=""/>
>>
>> </util:map>
>>
>>
>>
>> <jaxrs:serviceBeans>
>>
>> <ref bean="customerService"/>
>>
>> </jaxrs:serviceBeans>
>>
>>
>> Thanks
>>
>> Balaji
>>
>>
Re: problem while posting JSON text to RESTService
Posted by Sergey Beryozkin <sb...@progress.com>.
Hi
I think this entry is confusing Jettison on the read side :
> <entry key="http://www.w3.org/2001/XMLSchema-instance" value=""/>
and you probably do not need it on the write side either, instead, just set a boolean "writeXsiType"
to false if you do not need the hierarchy info to go on the wire
let us know please if it helps
Cheers, Sergey
> Hi All,
>
>
>
> I have problem while posting JSON text to RESTService. The service is
> failing with Exception
>
> JAXBException occurred : unexpected element (uri:"
> http://www.w3.org/2001/XMLSchema-instance", local:"Customer"). Expected
> elements are <{}Customer>. unexpected element (uri:"
> http://www.w3.org/2001/XMLSchema-instance", local:"Customer"). Expected
> elements are <{}Customer>.
>
> I believe this the problem with namespace. Pleas suggest me a solution
>
>
>
>
>
> JSON Text
>
> -----------------
>
> {"Customer":{"id":123,"name":"Balaji"}}
>
>
>
>
>
> Customer Service
>
> ------------------
>
> @Path("/customerservice/")
>
> public class CustomerService {
>
> @POST
>
> @Path("/customers/")
>
> public Response addCustomer(Customer customer) {
>
> System.out.println("----invoking addCustomer, Customer name is: " +
> customer.getName());
>
> customer.setId(++currentId);
>
>
>
> customers.put(customer.getId(), customer);
>
>
>
> return Response.ok(customer).build();
>
> }
>
> }
>
>
>
> Spring-config.xml
>
> --------------
>
> <util:map id="jsonNamespaceMap" map-class="java.util.Hashtable">
>
> <entry key="http://www.w3.org/2001/XMLSchema-instance" value=""/>
>
> </util:map>
>
>
>
> <jaxrs:serviceBeans>
>
> <ref bean="customerService"/>
>
> </jaxrs:serviceBeans>
>
>
> Thanks
>
> Balaji
>