【问题标题】:Cooperation MongoDB lazy loading with Jackson @JsonIgnore in SpringBoot Rest ControllerSpringBoot Rest Controller中与Jackson@JsonIgnore合作MongoDB延迟加载
【发布时间】:2020-01-23 15:41:07
【问题描述】:

我在我的SpringBoot 应用程序中写了一个RestController。我也在使用MongoDB。这是我的实体:

public class LocationEntity {

    @Id
    private String id;

    private String name;

    @DBRef(lazy = true)
    @JsonIgnore
    private UserEntity owner;

    private String description;

    @DBRef(lazy = true)
    private List<RoleEntity> roles;

    private Date date;

    public LocationEntity(String name, UserEntity owner, String description, List<RoleEntity> roles, Date date) {
         this.name = name;
         this.owner = owner;
         this.description = description;
         this.roles = roles;
         this.date = date;
    }
}

RoleEntityUserEntity 也是来自同一数据库的实体。 我的RestController 的方法返回ResponseEntity,所以默认使用Jackson 内部将Object 序列化为JSON。 我想准确地询问延迟加载。如果我使用Jackson 中的@JsonIgnore 在序列化中忽略该字段,ORM 会不会从数据库中获取“惰性字段”

提前感谢您的帮助!

【问题讨论】:

    标签: java mongodb orm jackson lazy-loading


    【解决方案1】:

    ORM 只会在需要时获取那些延迟加载的字段。这意味着如果您指示 Jackson 在序列化期间忽略它们(使用 @JsonIgnore 注释),ORM 将不会获取它们。

    【讨论】:

      猜你喜欢
      • 2017-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-05
      • 1970-01-01
      • 1970-01-01
      • 2015-09-30
      相关资源
      最近更新 更多