如何在spring-data-rest中防止relTargetType的json输出?

mem*_*und 6 java spring spring-data-rest

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

@RepositoryRestResource(collectionResourceRel = "myContent", path = "myContent")
public interface MyContentRepository extends PagingAndSortingRepository<MyContentEntity, Long> {

}
Run Code Online (Sandbox Code Playgroud)

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

  "content" : [ {
    "value" : [ ],
    "rel" : null,
    "collectionValue" : true,
    "relTargetType" : "com.domain.MyContentEntity"
  } ],
Run Code Online (Sandbox Code Playgroud)

问题:如何防止公开relTargetType包和"真实"域名?

Jon*_*ing 1

在你的 POJO 中:

如果您根本不希望 JSON 中包含 relTargetType:

@JsonIgnore
public String getRelTargetType() {
    return relTargetType;
}
Run Code Online (Sandbox Code Playgroud)

如果你只是想隐藏包:

public String getRelTargetType() {
    return relTargetType.split("\\.")[2];
}
Run Code Online (Sandbox Code Playgroud)

如果你想隐藏包并返回不同的域名:

public String getRelTargetType() {
    return "AlteredDomainName";
}
Run Code Online (Sandbox Code Playgroud)