java - Spring 400 错误请求错误

标签 java json spring rest

我收到此错误,请问是什么原因导致的? 我正在尝试发送一个 DTO,它有一个扩展抽象类的对象列表。我认为这个问题可能是由于 DTO 中的列表或抽象类的子类导致的?

@Autowired
private RestClient restClient;


@Override
public ReceiptDto create_TicketIdentifier_For_Sale(TicketSaleDto tiDto)
        throws ServiceException {

    RestTemplate restTemplate = this.restClient.getRestTemplate();
    String url = this.restClient.createServiceUrl("/ticketIdentifier/");
    HttpHeaders headers = this.restClient.getHttpHeaders();
    //headers.add("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE);
    HttpEntity<TicketSaleDto> entity = new HttpEntity<>(tiDto, headers);

    ReceiptDto ti = null;
    try {
        ParameterizedTypeReference<ReceiptDto> ref = new ParameterizedTypeReference<ReceiptDto>() {};
        ResponseEntity<ReceiptDto> response = restTemplate.exchange(URI.create(url), HttpMethod.POST, entity, ref);
        ti = response.getBody();
        //  System.out.println(ti.getEntryDto().getReceiptDto().getCustomerDto().getLastname());
    } catch (RestClientException e) {
        e.getStackTrace();
        throw new ServiceException("Could not retrieve ticketIdentifiers: " + e.getMessage());
    }
    return ti;  

2014-12-13T02:21:34,867 [JavaFX Application Thread] DEBUG http.wire - http-outgoing-0 << "HTTP/1.1 400 Bad Request[\r][\n]"
2014-12-13T02:21:34,867 [JavaFX Application Thread] DEBUG http.wire - http-outgoing-0 << "Date: Sat, 13 Dec 2014 01:21:34 GMT[\r][\n]"
2014-12-13T02:21:34,867 [JavaFX Application Thread] DEBUG http.wire - http-outgoing-0 << "Content-Type: text/html; charset=ISO-8859-1[\r][\n]"
2014-12-13T02:21:34,867 [JavaFX Application Thread] DEBUG http.wire - http-outgoing-0 << "Cache-Control: must-revalidate,no-cache,no-store[\r][\n]"
2014-12-13T02:21:34,867 [JavaFX Application Thread] DEBUG http.wire - http-outgoing-0 << "Content-Length: 316[\r][\n]"
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG http.wire - http-outgoing-0 << "Server: Jetty(9.2.2.v20140723)[\r][\n]"
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG http.wire - http-outgoing-0 << "[\r][\n]"
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG http.wire - http-outgoing-0 << "<html>[\n]"
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG http.wire - http-outgoing-0 << "<head>[\n]"
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG http.wire - http-outgoing-0 << "<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>[\n]"
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG http.wire - http-outgoing-0 << "<title>Error 400 Bad Request</title>[\n]"
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG http.wire - http-outgoing-0 << "</head>[\n]"
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG http.wire - http-outgoing-0 << "<body><h2>HTTP ERROR 400</h2>[\n]"
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG http.wire - http-outgoing-0 << "<p>Problem accessing /ticketline/ticketIdentifier/. Reason:[\n]"
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG http.wire - http-outgoing-0 << "<pre>    Bad Request</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>[\n]"
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG http.wire - http-outgoing-0 << "[\n]"
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG http.wire - http-outgoing-0 << "</body>[\n]"
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG http.wire - http-outgoing-0 << "</html>[\n]"
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG http.headers - http-outgoing-0 << HTTP/1.1 400 Bad Request
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG http.headers - http-outgoing-0 << Date: Sat, 13 Dec 2014 01:21:34 GMT
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG http.headers - http-outgoing-0 << Content-Type: text/html; charset=ISO-8859-1
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG http.headers - http-outgoing-0 << Cache-Control: must-revalidate,no-cache,no-store
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG http.headers - http-outgoing-0 << Content-Length: 316
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG http.headers - http-outgoing-0 << Server: Jetty(9.2.2.v20140723)
2014-12-13T02:21:34,868 [JavaFX Application Thread] DEBUG execchain.MainClientExec - Connection can be kept alive indefinitely
2014-12-13T02:21:34,868 [JavaFX Application Thread] WARN  client.RestTemplate - POST request for "http://localhost:8080/ticketline/ticketIdentifier/" resulted in 400 (Bad Request); invoking error handler
2014-12-13T02:21:34,868 [JavaFX Application Thread] WARN  client.RestTemplate - POST request for "http://localhost:8080/ticketline/ticketIdentifier/" resulted in 400 (Bad Request); invoking error handler
2014-12-13T02:21:34,870 [JavaFX Application Thread] DEBUG conn.PoolingHttpClientConnectionManager - Connection [id: 0][route: {}->http://localhost:8080] can be kept alive indefinitely
2014-12-13T02:21:34,870 [JavaFX Application Thread] DEBUG conn.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {}->http://localhost:8080][total kept alive: 1; route allocated: 1 of 2; total allocated: 1 of 20]
2014-12-13T02:21:34,871 [JavaFX Application Thread] DEBUG controller.TicketingProcessController - Could not retrieve ticketIdentifiers: 400 Bad Request

最佳答案

解决方案在这里..子类的一些定义解决了我的问题.. http://www.sureshpw.com/2013/09/javajson-polymorphic-mapping-using.html

关于java - Spring 400 错误请求错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27454696/

相关文章:

java - org.json.JSONObject 可以生成 {"und":[ {"value" :"some@one.com"}]}?

jquery - svn日志输出json格式

java - 理解tomcat/spring boot多线程

java - intellij java桌面应用程序如何使用资源

java - 如何在声明实例之前将类方法作为参数传递?

java - 数组中的位置不允许为 int

json - 如何在Cloudformation中指定JSON格式的字符串?

java - Spring - 无法强制作为 CGLIB 代理的类转换异常

java - `Point-Cuts`和 `Advices`仅适用于Spring中的bean吗?

java - 非 volatile 字段何时写入主存