Search code examples
javaspring-bootjax-rsbigdecimaldto

BigDecimal attribute in request dto class always maps null irrespective of what is passed in API request


For the following entry point -

@Path("api/endpoint")
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
public CustomerInducedLimitsUpdateResponse customerInducedLimit(@FormParam("type") String type, @FormParam("interval") String interval, @BeanParam LimitsDto dto,
        @Context SecurityContext security) {

Dto class definition -

public class LimitsDto {
    @FormParam("perTxnLimit") private BigDecimal perTxnLimit;
    @FormParam("value") private BigDecimal value;
    @FormParam("count") private BigDecimal count;

    public BigDecimal getPerTxnLimit() {
        return perTxnLimit;
    }
    public void setPerTxnLimit(BigDecimal perTxnLimit) {
        this.perTxnLimit = perTxnLimit;
    }
    public BigDecimal getValue() {
        return value;
    }
    public void setValue(BigDecimal value) {
        this.value = value;
    }
    public BigDecimal getCount() {
        return count;
    }
    public void setCount(BigDecimal count) {
        this.count = count;
    }
}

For the following API call -

curl -X POST \
  http://127.0.0.1:8084/api/endpoint \
  -H 'Authorization: Bearer <id>' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'perTxLimit=100&value=100&count=101&type=load&interval=daily'

Inspecting the value of dto object shows perTxnLimit set as null -

enter image description here

How do I fix this? What am I missing here?


Solution

  • Probably the only issue, that you have is, that: you invoke request with perTxLimit parameter, but expect perTxnLimit parameter. So just a little typo & (me) hashing for some rep. :)) Welcome!