I made a ajax post call in the front end.
let data = {
marketplaceId: "1",
monetaryAmount: {
amount: 100,
currencyCode: "USD",
},
}
$.post(posturl, data, function(returnedData) {
console.log(returnedData)
}
).fail(function() {
console.log("error")
})
In my spring mvc controller, I want to map monetaryAmount json object to A java object SimpleAmount.
SimpleAmount.java
public class SimpleAmount {
private BigDecimal amount;
private String currencyCode;
public BigDecimal getAmount() {
return this.amount;
}
public void setAmount(BigDecimal amount) {
this.amount = amount;
}
public String getCurrencyCode() {
return this.currencyCode;
}
public void setCurrencyCode(String currencyCode) {
this.currencyCode = currencyCode;
}
}
Controller.java
@RestController
public class Controller {
@RequestMapping(value = "/rpl/updateasinlimit", method = RequestMethod.POST)
@ResponseBody
public BGCServiceResponseStatus updateAsinLimit(
@RequestParam Long marketplaceId,
@RequestParam @RequestBody SimpleAmount monetaryAmount) {
......
}
}
However, SimpleAmount monetaryAmount
never gets mapped properly. It seems to me that all those primitive type will get mapped easily, but not java object
But I dont know how I can map json object sent from ajax post to the parameter passed into spring controller?