cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sergey Beryozkin" <sbery...@progress.com>
Subject Re: JSON in CXF
Date Mon, 06 Apr 2009 11:01:26 GMT
Hi Gary
>>
>> I ended up writing my own converter for JSON that uses its own annotations
>> seperate from JAXB.  It's a pretty quick implementation, and only does what
>> I need it to do.  It depends on the JSON objects from json.org, which are
>> also included in Jettison under a different package.  The annotations can be
>> used alongside JAXB like so:
>>
>> @XmlRootElement(name = "response")
>> @JsonObject
>> public class MyResponse {
>>  @XmlAttribute
>>  @JsonField
>>  private boolean success;
>>  @XmlElement(name = "msg")
>>  @JsonField(name = "msg")
>>  private String message;
>>  @XmlElementWrapper(name = "errors")
>>  @XmlElement(name = "error")
>>  @JsonField(name = "errors", required = true)
>>  private List<String> errors;
>>  ...
>> }

Would you be interested in updating the existing CXF JSONProvider (the one based on Jettison)
for it to support @JsonObject/etc 
annotations ? I was about to do it myself but given my JSON experience (not great so to say)
I thought I would ping you first :-)
we can introduce a new package, org.apache.cxf.jaxrs.providers.json, or org.apache.cxf.jaxrs.ext.json,
and add these annotations 
there, and then rely on the fact Jettison ships JSonObject/etc...

cheers, Sergey

>>
>> This will produce this JSON:
>>
>> {success: true, msg: "Test Message", errors: ["a", "b"]}
>>
>> And this XML:
>>
>> <response success="true"><msg>Test
>> Message</msg><errors><error>a</error><error>b</error></errors></response>
>>
>> Since this was written only for personal use, it's a fair bit aways from
>> being a full-featured library.  Stuff that needs to be done before public
>> consumption:
>>
>> 1) Two-way serialization.  Currently it's only bean -> JSON but not the
>> other way around.
>> 2) Reflection caching.  Currently all reflection happens in the middle of
>> serialization.  Breaking it up into reflection + serialization phases as
>> JAXB does it would speed things up considerably.
>> 3) Ability to switch between field/method accessors (currently it only reads
>> fields)
>>
>> As well as some features that could be really useful such as:
>>
>> 1) Pluggable annotation adapters that can be used to read directly from JAXB
>> annotations
>> 2) Type adapters that will allow custom marshalling/unmarshalling, although
>> this could also be done via getters/setters
>>
>> What's the interest level in putting something like this into CXF?
>>
>> Cheers,
>> Gary
>>


Mime
View raw message