Serializer for (Hash)Maps for Jersey use?
===

I'm trying to POST the following payload to my Jersey-based web service:

    {
        "firstname":"Jimmy",
        "lastname":"Johns",
        "addresses":
        [
            {
                "street":"19 Mayberry Drive",
                "city":"Mayberry",
                "state":"nc",
                "postalcode":"27043",
                "country":"us",
                "addresstype":1
            }
        ],
        "data":
        {
            "eyes":"blue",
            "hair":"brown",
            "sandwich":"roast beef"
        }
    }

My Jersey code:

    @POST
    public Response create( Person person )
    {
        createBo( person );    <------- stopped here in debugger
        ...

Stopped just as Jersey calls me, I see addresses in *person* flushed out with exactly what I'm looking for (what's in the JSON above). However, my data tuples aren't there. I know Jersey is calling my no-arg constructor for *Address* es and its setters are getting called, but I'm up in the night as far as what Jersey might or might not be trying to do with these random ("data") tuples in my JSON. (I say "random" because in a different invocation, these might be "cave":"deep, dark", "mountain":"high, wide", etc. This is part and parcel of my interface.)

To flesh out what I'm talking about, consider these POJOs as context for the above:

    @XmlAccessorType( XmlAccessType.FIELD )
    @XmlRootElement
    public class Person implements Serializable
    {
        @XmlElement
        private List< Address > addresses = new ArrayList< Address >();
    
        @XmlElement
        private Map< String, String > data = new HashMap< String, String >();
    
        ...

    @XmlRootElement
    public class Address implements Serializable
    {
        private String  street;
        private String  city;
        private String  state;
        private String  country;
        private String  postalcode;
        private Integer addresstype;
        ...

Note: I can't do the random tuples as I've done *Address* because I don't actually know beforehand what the keys will be (whereas I limit *Address* to *street*, *city*, etc.).

What I need is some kind of magic serializer for *HashMap*s in Jersey and I cannot seem to interpret the docs well enough to understand how to write one or work around this problem while still maintaining the flexibility of my interface.

I would appreciate any indication as to how to accomplish this.

Russ Bateman

P.S. Note sadly that http://stackoverflow.com/questions/5794713/java-util-map-to-json-object-with-jersey-jaxb-jackson was not helpful, though it showed great promise.



