Spring MVC REST using @RequestBody List<?> returns HTTP 400 syntactically incorrect -
i using spring 4 + jackson 2 , have written functional post method using @requestbody on custom class. method has no trouble unmarshalling object.
@responsebody @requestmapping(value="store", method = requestmethod.post) public serviceresponse store(@requestbody customclass list) { ... } // request: { code: "a", amount: 200 }
when attempted add method handle collection of same class instead, post requests returning following error.
http status 400: request sent client syntactically incorrect.
i note error typically occurs when json submitted not match entity class. however, doing submitting array of same object instead of object itself, has proven work.
@responsebody @requestmapping(value="store-bulk", method = requestmethod.post) public serviceresponse storebulk(@requestbody list<customclass> list) { ... } // request: [{ code: "a", amount: 200 }, { code: "b", amount: 400 }]
am missing here?
in java, type information generics erased @ runtime, spring sees list<customclass> object
list<object> object
, cannot understand how parse it.
one of ways solve it, capture type information creating wrapper class list, this:
public class customclasslist extends arraylist<customclass> { }
Comments
Post a Comment