Reputation: 45
I know spring 3.2 does convert a json to a list of objects with RequestBody annotation. Its not working for me. I can use regular Jackson object mapper to do it. Just checking if any one can help me.. Below is my json and controller method
[{"uniqueJqGridId":"1","fileProcessingDate":"2012-09-24","createdTimeStamp":"1348569180191","csoCode":"A-A ","cycleDate":"2012-09-24","accountDate":"2012-10-02","originName":"NCAA ","amount":"-95996.33","policyNumber":"C ","transactionCode":"PCH","id":"1"}]
@RequestMapping(method = RequestMethod.POST, value = "/washTransactions", headers="Content-Type=application/json")
public @ResponseBody RequestStatus washTransactions(@RequestBody List<ReconPolicy> policiesToWash)throws Exception{
reconciliationService.applyWashToTransactions(policiesToWash,getCurrentUser());
return new RequestStatus(true);
}
Upvotes: 0
Views: 705
Reputation: 45
Thanks for you reply Varun. Starting from Spring 3.2,There is no type erasure problem. I found the issue after enabling spring debugging, I figure out it is failing on some unknown properties, I had to annotate my class with @JsonIgnoreProperties. Now it works.
Upvotes: 0
Reputation: 15109
You're facing Java's Type Erasure problem. Spring is not able to pass the exact class type to the method so it's actually getting something like List<?> policiesToWash
.
A workaround would be to create a class like
public class WashablePolishes extends ArrayList<ReconPolicy>
This way spring will retain the type through the super type chain.
or you could change your method to
public @ResponseBody RequestStatus washTransactions(@RequestBody ReconPolicy[] policiesToWash) throws Exception {...}
Upvotes: 1