You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by mgibble <mg...@bandwidth.com> on 2007/11/27 21:28:36 UTC

Empty string namespace mapping with JSON and HTTP Post

I am using the restful_http_binding sample and I have changed the following
lines:

        // Set up the JSON StAX implementation
        Map<String, String> nstojns = new HashMap<String, String>();
        nstojns.put("http://customer.acme.com", "acme");

to:

        // Set up the JSON StAX implementation
        Map<String, String> nstojns = new HashMap<String, String>();
        nstojns.put("http://customer.acme.com", "");

I do an HTTP Post according to the README using wget with the following
add.json file:

{ 
  "Customer" : {
    "name" : "Jim Bob"
  }
}

I would have thought that this would have worked, but the Customer parameter
of the addCustomer method is not populated with any data.  However, if I
change the add.json file to:

{ 
  ".Customer" : {
    ".name" : "Jim Bob"
  }
}

the Customer parameter is populated appropriately.  I would have thought
that with the mapping of "customer.acme.com" to "" that my original JSON
would have worked and not required a period ('.') before each field name. 
Am I misunderstanding or is this a bug?  If so, is there a way that I can
achieve the functionality that I desire?

Thanks.
-- 
View this message in context: http://www.nabble.com/Empty-string-namespace-mapping-with-JSON-and-HTTP-Post-tf4884221.html#a13979132
Sent from the cxf-user mailing list archive at Nabble.com.


RE: Empty string namespace mapping with JSON and HTTP Post

Posted by hohteri <ha...@tecnomen.com>.
As did I. Sent a patch: http://jira.codehaus.org/browse/JETTISON-34

Harri


mgibble wrote:
> 
> Actually, I believe the link you sent illustrates what I am expecting to
> see, but am not:
> 

-- 
View this message in context: http://www.nabble.com/Empty-string-namespace-mapping-with-JSON-and-HTTP-Post-tp13979132p15547593.html
Sent from the cxf-user mailing list archive at Nabble.com.


RE: Empty string namespace mapping with JSON and HTTP Post

Posted by mgibble <mg...@bandwidth.com>.
Actually, I believe the link you sent illustrates what I am expecting to see,
but am not:

- The best way to demonstrate the Mapped convention is a short example:
- <price xmlns="http://acme.com">10.00</price>
- 
- Using the mapped convention this can be turned into:
- { "acme.price" : { "10.00" }
- As you can see we've mapped the http://acme.com namespace to the "acme."
prefix. This creates a very readable format.

Notice that it says that the http://acme.com namespace has been mapped to
the "acme." prefix: acme with a period on the end.  Therefore, I would
assume that if the http://acme.com namespace was mapped to "" that the JSON
would be:

{ "price" : { "10.00" }

However, it is not mapping that way, but instead is mapping to:

{ ".price" : { "10.00" }

In addition, it is worth noting that the JSON on the response of the
restful_http_binding sample is exactly as I would expect it, i.e. it has no
prepended period, but the period is needed on input.  Is there a reason that
this would work differently on input versus output?


Liu, Jervis wrote:
> 
>> -----Original Message-----
>> From: mgibble [mailto:mgibble@bandwidth.com]
>> Sent: 2007年11月28日 4:29
>> To: cxf-user@incubator.apache.org
>> Subject: Empty string namespace mapping with JSON and HTTP Post
>> 
>> 
>> I am using the restful_http_binding sample and I have changed the
>> following
>> lines:
>> 
>>         // Set up the JSON StAX implementation
>>         Map<String, String> nstojns = new HashMap<String, String>();
>>         nstojns.put("http://customer.acme.com", "acme");
>> 
>> to:
>> 
>>         // Set up the JSON StAX implementation
>>         Map<String, String> nstojns = new HashMap<String, String>();
>>         nstojns.put("http://customer.acme.com", "");
>> 
>> I do an HTTP Post according to the README using wget with the following
>> add.json file:
>> 
>> {
>>   "Customer" : {
>>     "name" : "Jim Bob"
>>   }
>> }
>> 
>> I would have thought that this would have worked, but the Customer
>> parameter
>> of the addCustomer method is not populated with any data.  However, if I
>> change the add.json file to:
>> 
>> {
>>   ".Customer" : {
>>     ".name" : "Jim Bob"
>>   }
>> }
>> 
>> the Customer parameter is populated appropriately.  I would have thought
>> that with the mapping of "customer.acme.com" to "" that my original JSON
>> would have worked and not required a period ('.') before each field name.
>> Am I misunderstanding or is this a bug?  If so, is there a way that I can
>> achieve the functionality that I desire?
> 
> This is expected behavior. CXF HTTP binding is using Jettison to do the
> JSON/XML mappings. [1] explaines how the default mapping works. You can
> also try the BadgerFish convention. 
> 
> [1]. http://jettison.codehaus.org/User%27s+Guide
> 
>> 
>> Thanks.
>> --
>> View this message in context:
>> http://www.nabble.com/Empty-string-namespace-mapping-with-JSON-and-
>> HTTP-Post-tf4884221.html#a13979132
>> Sent from the cxf-user mailing list archive at Nabble.com.
> 
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
> 
> 

-- 
View this message in context: http://www.nabble.com/Empty-string-namespace-mapping-with-JSON-and-HTTP-Post-tf4884221.html#a13992546
Sent from the cxf-user mailing list archive at Nabble.com.


RE: Empty string namespace mapping with JSON and HTTP Post

Posted by "Liu, Jervis" <jl...@iona.com>.
> -----Original Message-----
> From: mgibble [mailto:mgibble@bandwidth.com]
> Sent: 2007年11月28日 4:29
> To: cxf-user@incubator.apache.org
> Subject: Empty string namespace mapping with JSON and HTTP Post
> 
> 
> I am using the restful_http_binding sample and I have changed the following
> lines:
> 
>         // Set up the JSON StAX implementation
>         Map<String, String> nstojns = new HashMap<String, String>();
>         nstojns.put("http://customer.acme.com", "acme");
> 
> to:
> 
>         // Set up the JSON StAX implementation
>         Map<String, String> nstojns = new HashMap<String, String>();
>         nstojns.put("http://customer.acme.com", "");
> 
> I do an HTTP Post according to the README using wget with the following
> add.json file:
> 
> {
>   "Customer" : {
>     "name" : "Jim Bob"
>   }
> }
> 
> I would have thought that this would have worked, but the Customer
> parameter
> of the addCustomer method is not populated with any data.  However, if I
> change the add.json file to:
> 
> {
>   ".Customer" : {
>     ".name" : "Jim Bob"
>   }
> }
> 
> the Customer parameter is populated appropriately.  I would have thought
> that with the mapping of "customer.acme.com" to "" that my original JSON
> would have worked and not required a period ('.') before each field name.
> Am I misunderstanding or is this a bug?  If so, is there a way that I can
> achieve the functionality that I desire?

This is expected behavior. CXF HTTP binding is using Jettison to do the JSON/XML mappings. [1] explaines how the default mapping works. You can also try the BadgerFish convention. 

[1]. http://jettison.codehaus.org/User%27s+Guide

> 
> Thanks.
> --
> View this message in context:
> http://www.nabble.com/Empty-string-namespace-mapping-with-JSON-and-
> HTTP-Post-tf4884221.html#a13979132
> Sent from the cxf-user mailing list archive at Nabble.com.

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland