微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – 如何在spring-data-rest中阻止relTargetType的json输出?

我正在创建一个@RepositoryRestResource并将其导出为rest服务,如下所示:

@RepositoryRestResource(collectionResourceRel = "myContent",path = "myContent")
public interface MyContentRepository extends PagingAndSortingRepository

问题:当我请求内容时,我得到以下摘录:

  "content" : [ {
    "value" : [ ],"rel" : null,"collectionValue" : true,"reltargettype" : "com.domain.MyContentEntity"
  } ],

问题:如何防止暴露reltargettype包和“真实”域名?

最佳答案
在您的POJO中:

如果您根本不想在JSON中使用reltargettype

@JsonIgnore
public String getReltargettype() {
    return reltargettype;
}

如果您只想隐藏包裹:

public String getReltargettype() {
    return reltargettype.split("\\.")[2];
}

如果要隐藏包并返回其他域名:

public String getReltargettype() {
    return "AlteredDomainName";
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐