繁体   English   中英

Spring REST模板的怪异行为

[英]Weired behavior with Spring REST Template

这是我的要求课

    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 + "]";
    }
}

这是我的服务班

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);
        }

其余调用按预期工作正常,但问题是请求对象中的第三个参数发送了两次,例如:

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

最后一个参数以所有小字符发送两次

通过为我的getter和setter使用正确的Java命名约定,解决了该问题。

为什么仍然如此,为什么Spring与命名约定如此紧密地结合在一起。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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