【问题标题】:Spring boot 2.0.0.BUILD-SNAPSHOT rest: Can not override _serializer?Spring boot 2.0.0.BUILD-SNAPSHOT 休息:不能覆盖_serializer?
【发布时间】:2017-09-11 22:44:22
【问题描述】:

使用 gradle 刷新我的 spring boot 项目后,出现以下错误:

{
  "timestamp": 1492300922752,
  "status": 500,
  "error": "Internal Server Error",
  "exception": "org.springframework.http.converter.HttpMessageNotWritableException",
  "message": "Could not write JSON document: Can not override _serializer: had a org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module$NestedEntitySerializer, trying to set to com.fasterxml.jackson.databind.ser.std.StringSerializer (through reference chain: org.springframework.hateoas.PagedResources[\"_embedded\"]->java.util.Collections$UnmodifiableMap[\"orders\"]->java.util.ArrayList[0]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not override _serializer: had a org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module$NestedEntitySerializer, trying to set to com.fasterxml.jackson.databind.ser.std.StringSerializer (through reference chain: org.springframework.hateoas.PagedResources[\"_embedded\"]->java.util.Collections$UnmodifiableMap[\"orders\"]->java.util.ArrayList[0])",
  "path": "/orders"
}

我使用 2.0.0.BUILD-SNAPSHOT

2017-04-16 02:00:58.845  INFO 36126 --- [  restartedMain] d.p.o.OrderRestServiceApplication        : Started OrderRestServiceApplication in 11.163 seconds (JVM running for 37480.653)
2017-04-16 02:02:02.714  INFO 36126 --- [nio-8083-exec-2] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-04-16 02:02:02.714  INFO 36126 --- [nio-8083-exec-2] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started
2017-04-16 02:02:02.717  INFO 36126 --- [nio-8083-exec-2] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 3 ms
2017-04-16 02:02:02.717 DEBUG 36126 --- [nio-8083-exec-2] o.s.b.w.s.f.OrderedRequestContextFilter  : Bound request context to thread: org.apache.catalina.connector.RequestFacade@5b2fb354
2017-04-16 02:02:02.724 DEBUG 36126 --- [nio-8083-exec-2] org.hibernate.SQL                        : select order0_.id as id1_1_, order0_.create_date as create_d2_1_, order0_.customer_id as customer3_1_, order0_.ordered_date as ordered_4_1_, order0_.payment_order_id as payment_5_1_, order0_.shipping_order_id as shipping6_1_, order0_.status as status7_1_ from orders order0_ limit ?
Hibernate: select order0_.id as id1_1_, order0_.create_date as create_d2_1_, order0_.customer_id as customer3_1_, order0_.ordered_date as ordered_4_1_, order0_.payment_order_id as payment_5_1_, order0_.shipping_order_id as shipping6_1_, order0_.status as status7_1_ from orders order0_ limit ?
2017-04-16 02:02:02.728 DEBUG 36126 --- [nio-8083-exec-2] org.hibernate.SQL                        : select count(order0_.id) as col_0_0_ from orders order0_
Hibernate: select count(order0_.id) as col_0_0_ from orders order0_
2017-04-16 02:02:02.749  WARN 36126 --- [nio-8083-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON document: Can not override _serializer: had a org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module$NestedEntitySerializer, trying to set to com.fasterxml.jackson.databind.ser.std.StringSerializer (through reference chain: org.springframework.hateoas.PagedResources["_embedded"]->java.util.Collections$UnmodifiableMap["orders"]->java.util.ArrayList[0]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not override _serializer: had a org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module$NestedEntitySerializer, trying to set to com.fasterxml.jackson.databind.ser.std.StringSerializer (through reference chain: org.springframework.hateoas.PagedResources["_embedded"]->java.util.Collections$UnmodifiableMap["orders"]->java.util.ArrayList[0])
2017-04-16 02:02:02.750  WARN 36126 --- [nio-8083-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON document: Can not override _serializer: had a org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module$NestedEntitySerializer, trying to set to com.fasterxml.jackson.databind.ser.std.StringSerializer (through reference chain: org.springframework.hateoas.PagedResources["_embedded"]->java.util.Collections$UnmodifiableMap["orders"]->java.util.ArrayList[0]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not override _serializer: had a org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module$NestedEntitySerializer, trying to set to com.fasterxml.jackson.databind.ser.std.StringSerializer (through reference chain: org.springframework.hateoas.PagedResources["_embedded"]->java.util.Collections$UnmodifiableMap["orders"]->java.util.ArrayList[0])
2017-04-16 02:02:02.750 DEBUG 36126 --- [nio-8083-exec-2] o.s.b.w.s.f.OrderedRequestContextFilter  : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@5b2fb354

【问题讨论】:

    标签: java hibernate spring-boot jackson


    【解决方案1】:

    我最近在使用 Spring Boot 2.0.0.M2 时遇到了同样的问题,但发现 2.0.0.M2 使用的 Jackson 版本存在缺陷。将其从2.9.0.pr3 降级为2.8.9。现在可以了。

    【讨论】:

    • 刚刚使用降级遇到了另一个问题。现在与2.0.0.BUILD-SNAPSHOT 合作。看起来还可以。
    【解决方案2】:

    我将我的项目降级到 springBootVersion 1.5.2.RELEASE

    【讨论】:

      猜你喜欢
      • 2018-07-16
      • 2013-12-09
      • 2017-08-31
      • 2021-10-28
      • 1970-01-01
      • 2015-05-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-10
      相关资源
      最近更新 更多