You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by Chaitanya <ch...@pramati.com> on 2009/07/03 10:23:54 UTC

Supprot for wrapped/unwrapped styles in Mapped convention for JSON

Hi, 

I have a JAX-RS method which takes an Employee object as a param. Employee class is given below.

@XmlRootElement
public class Employee {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

Unmarshalling of the JSON

{"employee":{"name":"abc"}}

works fine and gives an Employee object, but if the JSON input is

{"name":"abc"} 

unmarshalling fails.

Does CXF support both wrapped and unwrapped styles in Mapped convention for JSON?
If yes what should be done to make the second case work?

Thank you
Chaithanya.

Re: Supprot for wrapped/unwrapped styles in Mapped convention for JSON

Posted by Sergey Beryozkin <se...@iona.com>.
In fact, I can probably update JSON provider to do it. If it is set to
operate in 'unwrapped' mode then it will append a class name to the stream,
will do it shortly

cheers, Sergey


Sergey Beryozkin wrote:
> 
> Hi
> 
> I'm not sure yet - it appears JSONProvider may need to be updated to
> handle unwrapped cases.
> Does anyone know, is it already possible to do somehow in CXF ?
> 
> Perhaps one workaround is to register a RequestFilter which will replace
> an InputStream on the inbound message with another stream which will
> present
> 
> {"name":"abc"}
> 
> as
> 
> {"employee":{"name":"abc"}}
> 
> for small streams (JSON ones are probably all quite small) this should
> work quite well. what do you think ?
> 
> cheers, Sergey
> 
> 
> 
> Chaitanya-10 wrote:
>> 
>> Hi, 
>> 
>> I have a JAX-RS method which takes an Employee object as a param.
>> Employee class is given below.
>> 
>> @XmlRootElement
>> public class Employee {
>>     private String name;
>> 
>>     public String getName() {
>>         return name;
>>     }
>> 
>>     public void setName(String name) {
>>         this.name = name;
>>     }
>> }
>> 
>> Unmarshalling of the JSON
>> 
>> {"employee":{"name":"abc"}}
>> 
>> works fine and gives an Employee object, but if the JSON input is
>> 
>> {"name":"abc"} 
>> 
>> unmarshalling fails.
>> 
>> Does CXF support both wrapped and unwrapped styles in Mapped convention
>> for JSON?
>> If yes what should be done to make the second case work?
>> 
>> Thank you
>> Chaithanya.
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Supprot-for-wrapped-unwrapped-styles-in-Mapped-convention-for-JSON-tp24319534p24353228.html
Sent from the cxf-dev mailing list archive at Nabble.com.


Re: Supprot for wrapped/unwrapped styles in Mapped convention for JSON

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

I'm not sure yet - it appears JSONProvider may need to be updated to handle
unwrapped cases.
Does anyone know, is it already possible to do somehow in CXF ?

Perhaps one workaround is to register a RequestFilter which will replace an
InputStream on the inbound message with another stream which will present

{"name":"abc"}

as

{"employee":{"name":"abc"}}

for small streams (JSON ones are probably all quite small) this should work
quite well. what do you think ?

cheers, Sergey



Chaitanya-10 wrote:
> 
> Hi, 
> 
> I have a JAX-RS method which takes an Employee object as a param. Employee
> class is given below.
> 
> @XmlRootElement
> public class Employee {
>     private String name;
> 
>     public String getName() {
>         return name;
>     }
> 
>     public void setName(String name) {
>         this.name = name;
>     }
> }
> 
> Unmarshalling of the JSON
> 
> {"employee":{"name":"abc"}}
> 
> works fine and gives an Employee object, but if the JSON input is
> 
> {"name":"abc"} 
> 
> unmarshalling fails.
> 
> Does CXF support both wrapped and unwrapped styles in Mapped convention
> for JSON?
> If yes what should be done to make the second case work?
> 
> Thank you
> Chaithanya.
> 

-- 
View this message in context: http://www.nabble.com/Supprot-for-wrapped-unwrapped-styles-in-Mapped-convention-for-JSON-tp24319534p24353159.html
Sent from the cxf-dev mailing list archive at Nabble.com.