cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <sergey.beryoz...@iona.com>
Subject Re: JSON in CXF
Date Sat, 21 Feb 2009 12:26:39 GMT

Just FYI : http://jira.codehaus.org/browse/JETTISON-65

Hopefully it will be fixed in Jettison eventually though it's difficult to
predict when. As I said we can discuss the option of shipping a non-JAXB
based JSON provider but I reckon it is also worth enhancing the Jettison
when possible - so if you can recommend something else that may need to be
improved in the way  Jettison renders the data then let us know please

Cheers, Sergey  


Hi Gary

I think I understand the problem better. As far as Jettison is concerned, I
reckon we can open an enhancement request.

<snip/>

{
  title: "My Blog Post",
  text: "Test Blog",
  author: "Some Guy",
  comments: [{
    author: "Some Other Guy",
    text: "Test Comment"
  }]
}

The bean should look like:

class Post {
  private String title;
  private String text;
  private String author;
  private List<Comment> comments;
  ...
}

These are just the resonably intuitive response formats for each format. 
The problem is that the packaged providers (JSONProvider 
and JAXBElementProvider) cannot provide both formats from the same bean
without some ugly hacks.

Getting the bean to output the correct XML means that you end up with JSON
that looks like this:

{
  title: "My Blog Post",
  text: "Test Blog",
  author: "Some Guy",
  comments: {
    comment: [{
      author: "Some Other Guy",
      text: "Test Comment"
    }]
  }
}

And getting the bean to output the correct JSON means that you end up with
XML that looks like this:

<post>
  <title>My Blog Post</title>
  <text>Test Blog</title>
  <author>Some Guy</author>
  <comment>
    <author>Some Other Guy</author>
    <text>Test Comment</text>
  </comment>
</post>

The problem is that because the JSON provider piggybacks off the JAXB XML
annotations, you only get indirect control of the way the 
bean is marshalled, and if you need tight control over both the XML and JSON
representations, things get either messy or impossible.


-- 
View this message in context: http://www.nabble.com/JSON-in-CXF-tp21931013p22135534.html
Sent from the cxf-dev mailing list archive at Nabble.com.


Mime
View raw message