Hi Elias,

Please, I think I am the naive one around here as I'm just getting my feet
wet with Atom and Abdera. :-)

Agreed that JSON and XML are not so easily mapped to each other. The
xml:base/id/lang stuff slipped my mind as a potential issue. It seems that
all the xml:base handling is in the FOM* classes right? So the JSON support
always outputs the full IRIs?

And yes, it would not be that hard for a user to use Jettison with the
current APIs. I was just wondering if it made sense to use it instead of a
custom mapping. If no, thats OK, thats just one of the things I'm trying to
figure out.

- Dan

On 12/5/06, Elias Torres <[EMAIL PROTECTED]> wrote:


Dan Diephouse wrote:
> Been playing around with Abdera a little and was thinking about putting
> together a patch to use Jettison for its JSON support [1]. Jettison is a
> StAX implementation I wrote for use in CXF that can read/write JSON. It
can
> do so in different ways as well - like BadgerFish mode and mapped mode.
The
> current code seems to require a distinct knowledge of all the different
> Atom
> elements and how to serialize it to JSON. With Jettison the idea is you
can
> just reuse the existing stax code that you have.
>
> I think the one weekness of Jettison currently is that it doesn't have a
> "no
> namespace mode" where it just automatically ignores the namespace.
Jettison
> has a mapped mode where you can map namespaces to prefixes. So I can map
a
> namespace http://www.w3.org/2005/Atom to "atom" and it would output json
> like "atom.feed". You can also just specify an empty prefix:
>
> Map xmlNsToJSON = new HashMap();
> xmlNsToJSON.put("http://www.w3.org/2005/Atom";, "");
>
> XMLStreamWriter writer = new
> MappedXMLOutputFactory(xmlNsToJSON).newXMLStreamWriter();
> ...
>
> And get this out:
>
> { "feed" : { "title" : "...", "link" : { "@href" : "..." } ... } }
>
> Its not that much work to specify the mapping manually, but a no
namespace
> mode might be handy if a user has custom extension elements and they
just
> want to default to having no json prefix
>
> But I digress... To recap: to me the advantages would be:
> - No JSON module required in the build
> - Different JSON mappings are supported by Jettison
> - No need to maintain manual JSON mapping code
> - Reading is supported too (currently I only see a JSONWriter...)

I investigated many of the different automatic mappings for XML to JSON
and none of them satisfied my requirements. The main issue with all of
them is that XML is not so easily-mapped to JSON all of the time. It
really depends on the specific instance of the document. There are many
issues serializing Atom to JSON because of things like xml:base,
xml:lang, xml:id, etc. Additionally, Atom can have any element anywhere
in the document. These are the reasons why I purposefully chose to have
a specific JSON format writer and maintaining is not a big issue, since
that's the point of this project. We maintain the code that maps Atom to
Java/JSON/RDF etc. Since Jettison is automatic, anyone can just use
those three lines of code and serialize Atom to JSON, right?

Maybe I'm being naive, so please let me know if auto XML-JSON is the new
pink.

-Elias

>
> Thoughts? I can put together a patch real easy for this. Just wondering
if
> the patch should rip out the existing JSON support and replace it with
> Jettison, if I should add it as an incremental enhancement, or if I
should
> bugger off :-)
>
> - Dan
>
> 1. http://jettison.codehaus.org




--
Dan Diephouse
Envoi Solutions
http://envoisolutions.com | http://netzooid.com/blog

Reply via email to