users@jersey.java.net

Re: [Jersey] JSONObjectProvider doesn't check media type

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Thu, 11 Jun 2009 08:09:09 -0700

On Thu, Jun 11, 2009 at 1:46 AM, Martin Probst<mail_at_martin-probst.com> wrote:
...
> That seems a bit unfortunate. I was actually trying to write a
> JSON->XML converter as I find that a bit cleaner than XML->JSON (you
> don't loose type information like what field is an integer, and JSON's
> object model is a better fit for Java object structures).
>
> Is this a bug? At least, Jersey produces content that is obviously of
> the wrong media type.

Can't comment on bug part, but I am not sure I follow the argument for use case.
While JSON has less impedance to/from java objects, wouldn't the
simplest way be to build actual java objects and just serialize those
to whichever you actually need? (i.e. just return POJO, not json.org
ref implementations tree object)
Or are you trying to work around artifacts caused by mapped
conventions that are incurred when going through that route (depending
on json mapper used)?

If latter, JacksonJsonProvider can do 'natural' mapping from Beans (or
Map/List/Wrapper structure); similar to how JAXB works (within limits
set by xml/object mapping impedance).

-+ Tatu +-