JSON support in JAXB

Developers: Jakub Podlesak
Status: ongoing

Jersey supports JSON with JAXB using the badgerfish convention. This works OK but can produce JSON that is difficult for clients to consume.

Investigate better support for JSON with JAXB that easier for clients to consume.


Goal: "Easier to consume" may have different meaning based on concrete client requirements/capabilities.
The way should be in allowing users to configure the format which suits them best.

Configuration: The plan is to allow users to create their own JAXBContext instance and set the json/format related options on it.

JSON formats/notations: Currently jettison library is used by Jersey. Besides above mentioned badgerfish convention it supports so called mapped
convention. It should be at least possible to switch between the two and to specify namespace mapping for the mapping convention.

jMaki support: for jMaki widgets, mapped convention looks fine, but is not sufficient as is. Current issues: TBD

What needs to be implemented:

  1. Jersey: the mean to take JAXBContext from application and use it by message readers/writers
  2. JAXB: provide a way to set options for marshaller/unmarshaller directly via JAXBContext
  3. JAXB: integrate jettison/another lib into JAXB for JSON support
  4. JAXB: implement customizations for jMaki support

Labels

 
(None)
  1. Oct 16, 2007

    Arun.Gupta says:

    jMaki can used as the client for consuming JSON generated by Jersey. The jMaki d...

    jMaki can used as the client for consuming JSON generated by Jersey. The jMaki data models are documented at: http://wiki.java.net/bin/view/Projects/jMakiDataModels.

  2. Oct 16, 2007

    4894437 says:

    JAXWS JSON extension has an extension of badgerfish that works better with JAXB,...

    JAX-WS JSON extension has an extension of badgerfish that works better with JAXB, by taking advantages of the schema knowledge. It can also produce the type system for JSON.

    So please talk to us when you get to work on this, so that we can share the information.

    1. Oct 16, 2007

      4894437 says:

      For whatever reason SDN decided that my name is 4894437 my real name is Kohsuke ...

      For whatever reason SDN decided that my name is 4894437 — my real name is Kohsuke Kawaguchi.

  3. Jun 19

    adrianquark says:

    So far it seems all the Java JSON service implementations rely on deriving JSON ...

    So far it seems all the Java JSON service implementations rely on deriving JSON from XML, when it would be much simpler, and result in much cleaner JSON, to derive the representation directly from the underlying Java objects.

    In most cases, Java objects can be serialized directly to JSON in the obvious way (collections becoming arrays, primitive types becoming scalars, and objects becoming JSON "objects"). In most cases the context should provide sufficient type information for deserialization without any meta-data in the JSON; the only time when it won't is when a field has a non-final type, in which case we can use a convention like an "@java-type" property on the resulting JSON object to act as a type tag.

    I'm currently working on a JAX-WS/JSON webservice and I really miss this facility. The JAXB schema has some awkwardness imposed by the poor mapping between Java objects and XML, and using this as a basis for the JSON just makes things worse. Please consider providing at least the option to derive the JSON serialization directly from the Java (making use of JAXB annotations only where necessary to keep the JSON simple).

Sign up or Log in to add a comment or watch this page.

The individuals who post here are part of the extended Sun Microsystems community and they might not be employed or in any way formally affiliated with Sun Microsystems. The opinions expressed here are their own, are not necessarily reviewed in advance by anyone but the individual authors, and neither Sun nor any other party necessarily agrees with them.

Copyright 1994-2008 Sun Microsystems, Inc.
Powered by Atlassian Confluence
Sun Guidelines on Public Discourse Privacy Policy Terms of Use Trademarks Site Map Employment Investor Relations Contact