【发布时间】:2019-10-04 10:19:31
【问题描述】:
我有类似的 Java 类
@Data
public class Comment {
private Integer id; // should be used anyhow
private Long refId; // for internal purpose -> not be serialized
private String text; // should be used in QuickComment
private String patch; // should be included in PatchComment ONLY
private String status; // should be included in StatusComment ONLY
}
我有
@Data
public class Response{
private Comment statusComment;
private Comment patchComment;
}
我想过用JsonViewlike
public class Views{
public interface StatusComment{}
public interface PatchComment{}
}
并将它们应用到初始类
@Data
public class Comment {
@JsonView({Views.StatusComment.class, Views.PatchComment.class})
private Integer id; // should be used anyhow
private Long refId; // for internal purpose -> not be serialized
@JsonView({Views.StatusComment.class, Views.PatchComment.class})
private String text; // should be used anyhow
@JsonView(Views.PatchComment.class)
private String patch; // should be included in PatchComment ONLY
@JsonView(Views.StatusComment.class)
private String status; // should be included in StatusComment ONLY
}
还有Response
@Data
public class Response{
@JsonView(Views.StatusComment.class)
private Comment statusComment;
@JsonView(Views.PatchComment.class)
private Comment patchComment;
}
但不知何故,它完全失败了。它完全失败了,即。什么都没有过滤。龙目岛有问题吗?还是定义不正确?
【问题讨论】:
标签: java spring jackson lombok