简体   繁体   中英

Weired behavior with Spring REST Template

This is my request class

    public class TestRequest implements Serializable {
    private static final long serialVersionUID = 1L;
    private String vendorID = null;
    private String transactionID = null;
    @JsonProperty("TESTAction")
    private String TESTAction = null;

    public String getVendorID() {
        return vendorID;
    }
    public void setVendorID(String vendorID) {
        this.vendorID = vendorID;
    }

    public String getTransactionID() {
    return transactionID;
  }

  public void setTransactionID(String transactionID) {
    this.transactionID = transactionID;
  }

    public String getTESTAction() {
        return TESTAction;
    }

    public void setTESTAction(String TESTAction) {
        TESTAction = TESTAction;
    }

    @Override
    public String toString() {
        return "TestStatus [vendorID=" + vendorID + ", transactionID=" + transactionID + ", s TESTAction=" + TESTAction + "]";
    }
}

This is my service class

HttpEntity<TestRequest > requestEntity = new HttpEntity<>(request, headers);
        try {
            LOG.info("Calling REST: " + restUrl);
            responseEntity = restTemplate.postForEntity(restUrl, requestEntity, TestResponseResponse.class);
        } catch (Exception e) {
            LOG.error("Exception in sending data: " + request);
            LOG.error("Exception in sending data to ESL" + e);
            throw new TestRestException("Exception while calling rest service", e);
        }

The rest call is working fine as expected but the problem is the third parameter in the request object is sent twice eg:

{
"vendorID": "testvendor",
"transactionID" : "testtrans",
"TESTAction": "test action",
"testaction":"test action"
}

The last parameter is sent twice in all small characters

The issue was solved by using the correct java naming conventions for my getters and setters.

Its still weired why Spring is so tightly coupled with the naming conventions though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM