Dan Diephouse wrote: > 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?
That's my intent at least although the code hasn't been thoroughly tested. I think we are calling getHref() instead of getResolvedHref(). But anyways, that's the kinds of things we can do in a custom writer as opposed to one that reads it from XML. However, it's still unresolved how to map 80% of the most commonly used Atom elements into JSON without making it too complicated (e.g. doing string checks for '@' or maintaining $-namespaces) for the end-user. > > 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. I guess we could have "multiple" JSONWriters, but I'm not sure we are needing that just yet. I think that as we get more users, we'll be able to work out a good representation and stick with it. Maybe it's one of the automagic ones, maybe it's a custom one. -Elias > > - 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 >> > > >