RestTemplate spring boot返回null

时间:2018-02-12 12:06:42

标签: java spring rest spring-mvc spring-boot

请帮忙。我有以下代码:

CheckResponse checkResponse = restTemplate.postForObject(webServiceUrl,checkTaxesWrapper, CheckResponse.class);

CheckResponse是我的POJO,如下所示:

  @JsonIgnoreProperties(ignoreUnknown = true)
    @JsonPropertyOrder(
            {
                    "errorCode",
                    "errorMessage",
                    "merchantTransationId",
                    "totalFee",
                    "numberOfWarrants",
                    "warrantList"

            }
    )
    public class CheckResponse
    {
        private String errorCode;
        private String errorMessage;
        private String merchantTransactionId;
        private String totalFee;
        private String numberOfWarrants;
        private List<Warrant>warrantList;

        private double taxSum;
        private double total;

        public double getTaxSum() {
            return taxSum;
        }

        public void setTaxSum(double taxSum) {
            this.taxSum = taxSum;
        }

        public double getTotal() {
            return total;
        }

        public void setTotal(double total) {
            this.total = total;
        }

        public List<Warrant> getWarrantList() {
            return warrantList;
        }

        public void setWarrantList(List<Warrant> warrantList) {
            this.warrantList = warrantList;
        }

        public String getErrorCode() {
            return errorCode;
        }

        public void setErrorCode(String errorCode) {
            this.errorCode = errorCode;
        }

        public String getErrorMessage() {
            return errorMessage;
        }

        public void setErrorMessage(String errorMessage) {
            this.errorMessage = errorMessage;
        }

        public String getMerchantTransactionId() {
            return merchantTransactionId;
        }

        public void setMerchantTransactionId(String merchantTransactionId) {
            this.merchantTransactionId = merchantTransactionId;
        }

        public String getTotalFee() {
            return totalFee;
        }

        public void setTotalFee(String totalFee) {
            this.totalFee = totalFee;
        }

        public String getNumberOfWarrants() {
            return numberOfWarrants;
        }

        public void setNumberOfWarrants(String numberOfWarrants) {
            this.numberOfWarrants = numberOfWarrants;
        }

        @Override
        public String toString() {
            return "CheckResponse{" +
                    "errorCode='" + errorCode + '\'' +
                    ", errorMessage='" + errorMessage + '\'' +
                    ", merchantTransactionId='" + merchantTransactionId + '\'' +
                    ", totalFee='" + totalFee + '\'' +
                    ", numberOfWarrants='" + numberOfWarrants + '\'' +
                    '}';
        }
    }

正如您所见,我有看起来像这样的Warrant POJO:

    @JsonIgnoreProperties(ignoreUnknown = true)
    @JsonPropertyOrder(
            {
                    "amount",
                    "personalId",
                    "benRefModel",
                    "ordPartyRefNumber",
                    "sourceAccount",
                    "purpose",
                    "benAddress",
                    "actualAmount",
                    "benPlace",
                    "ordPartyPlace",
                    "nacinPlacanja",
                    "transactionID",
                    "transactionType",
                    "reservationId",
                    "urgency",
                    "purposeCode",
                    "benRefNumber",
                    "benName",
                    "ordPartyTime",
                    "ordPartyAddress",
                    "currency",
                    "currencyDate",
                    "destinationAmount",
                    "ordPartyRefModel",
                    "info"
            }
    )
    public class Warrant {
        @JsonProperty("amount")
        private String amount;
        @JsonProperty("personalId")
        private String personalId;
        @JsonProperty("benRefModel")
        private String benRefModel;
        @JsonProperty("ordPartyRefNumber")
        private static final String ordPartyRefNumber="";
        @JsonProperty("sourceAccount")
        private static final String sourceAccount="";

        @JsonProperty("purpose")
        private String purpose;
        @JsonProperty("benAddress")
        private String benAddress;
        @JsonProperty("actualAmount")
        private String actualAmount;
        @JsonProperty("benPlace")
        private String benPlace;



        @JsonProperty("ordPartyPlace")
        private  String ordPartyPlace;
        @JsonProperty("nacinPlacanja")
        private String nacinPlacanja="E";
        @JsonProperty("transactionID")
        private String transactionID;
        @JsonProperty("transactionType")
        private  String transactionType;
        @JsonProperty("reservationId")
        private String reservationId;
        @JsonProperty("urgency")
        private  String urgency;
        @JsonProperty("purposeCode")
        private  String purposeCode="253";
        @JsonProperty("benRefNumber")
        private String benRefNumber;
        @JsonProperty("benName")
        private String benName;
        @JsonProperty("ordPartyName")
        private String ordPartyName;
        @JsonProperty("ordPartyAddress")
        private String ordPartyAddress;
        @JsonProperty("currency")
        private String currency="941";
        @JsonProperty("currencyDate")
        private String currencyDate;
        @JsonProperty("destinationAccount")
        private String destinationAccount;
        @JsonProperty("ordPartyRefModel")
        private  String ordPartyRefModel="";
        @JsonProperty("info")
        private  String info;
    //getters and setters..
    }

我使用了拦截记录传出请求和结果响应的拦截器。我看到了回应:

 2018-02-12 12:47:50.798  WARN 1732 --- [nio-8083-exec-2] r.e.p.logging.LoggingRequestInterceptor  : ============================response begin==========================================
    2018-02-12 12:47:50.798  WARN 1732 --- [nio-8083-exec-2] r.e.p.logging.LoggingRequestInterceptor  : Status code  : 200
    2018-02-12 12:47:50.798  WARN 1732 --- [nio-8083-exec-2] r.e.p.logging.LoggingRequestInterceptor  : Status text  : OK
    2018-02-12 12:47:50.798  WARN 1732 --- [nio-8083-exec-2] r.e.p.logging.LoggingRequestInterceptor  : Headers      : {Date=[Mon, 12 Feb 2018 11:47:50 GMT], Server=[Apache], Keep-Alive=[timeout=5, max=100], Connection=[Keep-Alive], Transfer-Encoding=[chunked], Content-Type=[application/json;charset=utf-8]}
    2018-02-12 12:47:50.798  WARN 1732 --- [nio-8083-exec-2] r.e.p.logging.LoggingRequestInterceptor  : Response body: 

{"errorCode":"00","errorMessage":"Approved","merchantTransationId":"201802121247500094RLk","totalFee":50,"numberOfWarrants":1,"warrantList":[{"transactionID":"33519e05-ab21-4a2e-9fdd-f1bfd1104691","trnFee":50,"transactionId":63496411,"trnMessage":"","trnStatus":1,"realValueDate":"2018-02-12 11:47:50"}]}

但是resttemplate返回null ..我不知道为什么..这是堆栈跟踪:

  java.lang.NullPointerException: null
        at rs.euprava.payment.controller.rest.RestRequestsController.checkSelectedTaxes(RestRequestsController.java:268)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317)
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
        at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
        at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
        at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
        at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
        at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
        at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
        at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
        at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
        at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
        at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
        at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)
        at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
        at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:347)
        at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:263)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:108)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)

我感谢任何帮助。谢谢

1 个答案:

答案 0 :(得分:0)

您可以查看针对Warrant的pojo json注释吗?我认为它们应该与下面的相匹配:

@JsonProperty("transactionID")
private String transactionID;

@JsonProperty("trnFee")
private Integer trnFee;

@JsonProperty("transactionId")
private Integer transactionId;

@JsonProperty("trnMessage")
private String trnMessage;

@JsonProperty("trnStatus")
private Integer trnStatus;

@JsonProperty("realValueDate")
private String realValueDate;