Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent json output of relTargetType in spring-data-rest?

I'm creating a @RepositoryRestResource and export it as rest service as follows:

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

}

Problem: when I request the content, I'm getting the following excerpt:

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

Question: how can I prevent to expose the relTargetType package and "real" domain name?

like image 961
membersound Avatar asked Feb 05 '16 12:02

membersound


1 Answers

In your POJO:

If you don't want relTargetType in the JSON at all:

@JsonIgnore
public String getRelTargetType() {
    return relTargetType;
}

If you just want to hide the package:

public String getRelTargetType() {
    return relTargetType.split("\\.")[2];
}

If you want to hide the package and return a different domain name:

public String getRelTargetType() {
    return "AlteredDomainName";
}
like image 107
Jonathan Sterling Avatar answered Sep 28 '22 00:09

Jonathan Sterling