I'm trying to marshall a JSON object into a wrapper class that contains a generic object, as well as additional information about the object's signature.

public class Signable<T> {

    private T object;
    private String signature;

    public class Signable() {
       generateSignature();
    }

    /* Getters and setters  */
}

The wrapper class works fine as long as I construct it with the object already created, and it is able to produce the desired json

@RequestMapping(value="/test/json/return",method=RequestMethod.GET)
public @ResponseBody Signable<Cart> getTest()
{
    Cart cart = new Cart();
    // populate cart with OrderItems ...
    Signable<Cart> sign = new Signable<Cart>();
    sign.setObject(cart);
    return sign;
}

which is able to generate the expected output

{
   "object":{
        "orderItems":[
              {
                  "id": "****",
                  "desc": "asdlfj",
                  "price": 25.53
              }
        ]
   },
   "signature":"s9d94f9f9gdfg67d8678g6s87d6f7g6";
}

Which is the format I want. However, when trying to marshal the same json generated from Signable back into Signable, I receive the following error:

java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to Cart

For some reason it's not able to determine that "object" in the json should be mapped to the type of Cart (it just defaults to the LinkedHashMap), even though it's specified in method header.

@RequestMapping(value="/test/json/post",method=RequestMethod.POST)
public @ResponseBody Signable<Cart> postTest(@RequestBody Signable<Cart> sign)

Is there a way to explicitly say which types of objects you want to generate from the JSON to insert in place of a generic?

Any help would be greatly appreciated.

Thanks.

Edit
Report