小编Ant*_*tje的帖子

带有@JsonView 的 Spring Json 序列化返回关联的空对象

我有一个带有 JPA 和 JSON 序列化的 Spring-Boot-Project。我尝试使用 @JsonView 仅序列化指定的属性。它工作正常,但对于我在Order(例如order.user)中的关联,它序列化了空的 Json-Object。

我使用以下依赖项

  • Spring-Boot 2.0.1.RELEASE
  • Spring-Boot-Starter-JPA 2.0.1.RELEASE
  • Spring-Hateos 0.24.0.RELEASE

请参阅以下 Json 结果:

{
  "content" : {
    "orderResources" : [ {
      "receiptDate" : "2019-08-14",
      "state" : "BILL_CREATED",
      "user" : { },
      "employer" : { },
      "orderplace" : { },
      "propertyManagement" : null,
      "plannings" : [ { } ]
    }, {
      "receiptDate" : "2019-08-17",
      "state" : "BILL_CREATED",
      "user" : { },
      "employer" : { },
      "orderplace" : { },
      "propertyManagement" : …
Run Code Online (Sandbox Code Playgroud)

java spring-boot json-serialization

0
推荐指数
1
解决办法
809
查看次数

标签 统计

java ×1

json-serialization ×1

spring-boot ×1