Reputation: 187
I'm trying to convert below simple JSON to Java Object using com.fasterxml.jackson.core. I have problem with bonusAmount field setter method.
JSON:
{"amount":332.5, "bonusamount":3, "action":"Spend"}
Java class:
@JsonIgnoreProperties(ignoreUnknown = true)
public class GameRequest {
@JsonProperty("amount")
private BigDecimal amount;
@JsonProperty("bonusamount")
private BigDecimal bonusAmount;
@JsonProperty("action")
private String action;
.....
public BigDecimal getBonusAmount() {
return bonusAmount;
}
public void setBonusAmount(BigDecimal bonusAmount) {
this.bonusAmount = bonusAmount;
}
Value of bonusAmount field is NULL when I try to use it but if I change name of setter method from setBonusAmount to setBonusamount then it works. Can someone tell me why??
Upvotes: 0
Views: 189
Reputation: 2268
That is because you have renamed your field using @JsonProperty("bonusamount")
that means Jackson searches for a method named setBonusamount
(first char toUpperCase, rest stays the same)
Upvotes: 1