users@jersey.java.net

Re: [Jersey] HashMap to jason serialization

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Wed, 28 Jul 2010 08:19:06 -0700

On Wed, Jul 28, 2010 at 6:17 AM, Anil Datt <anildatt_at_hotmail.com> wrote:
> I am using the most recent version of JAX-RS bundle. Whe I convert from my
> java object which has the HahMap
>
>
> class class Msg {
> String command;
> HashMap<String,String> args;
> }
>
> it gets transformed to
>
> {"args":{"entry":[{"key":"button","value":"hello"},{"key":"url","value":"http://test"}]},"command":"display
> page"}
>
> How can i get rin of the "entry" keyword and the square brackets that
> represent the array. Is there any other data structure that i can use in
> place of hashmap?

If you used native Jackson mapper, you would get

{
  "args" : {
    "button" : "hello",
    "url", "http://test"
  },
  "command" : "display"
}

which is bit more intuitive. Jackson JAX-RS provider is included in
Jackson distribution (jackson-jaxrs-1.5.5.jar) and just needs to be
registered via JAX-RS provider interface. I think there are examples
of registration with jersey documentation now.

-+ Tatu +-