加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 01:29:58 所属栏目:大数据 来源:网络整理
导读:我正在创建一个@RepositoryRestResource并将其导出为rest服务,如下所示: @RepositoryRestResource(collectionResourceRel = "myContent",path = "myContent")public interface MyContentRepository extends PagingAndSortingRepository 问题:当我请求内容

我正在创建一个@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";
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读