1

I've a Class with details I want to hide. But I need to get it too. So I wrote a Projection. But it doesn't work as it should.

I'm writing School <> Teacher (and so on) model.

public class School{//...

has a Set<Teacher>.

This set shouldn't be visible from the 'main' path (which is School of course).

So here is the Projection:

@Projection(name = "noTeacher", types = {School.class})
public interface SchoolNoTeacher extends ProjectionModel {
    String getName();
    String getSkz();
}

no getTeachers()!

This is default in my Repository

@RepositoryRestResource(path = "school", excerptProjection = SchoolNoTeacher.class)
public interface SchoolRepository extends PagingAndSortingRepository<School, Long> {//...

But I want to handle the rest path myself. So I've a controller too.

@RestController
@RequestMapping(ScoolModel.api + "/school")
public class SchoolRestController {//...

And the Projection is not working. Any way to fix it?

rala
  • 895
  • 2
  • 18
  • 43

1 Answers1

1

Don't use a @RestController and a @RepositoryRestResource together. With Spring Data Rest, The RepositoryRestResource is essentially a Controller and a Repository combined together to produce a HATEOAS service endpoint.

If you need to customize your base URI, please refer to this answer.

Community
  • 1
  • 1
Shawn Sherwood
  • 1,968
  • 2
  • 19
  • 30