title: How to create custom PersistentEntityResourceAssembler with Spring Data REST
body: <p>I'm using Spring Boot 2.1, Spring Data REST, Spring HATEOAS, Hibernate 5.</p>
  
  <p>I'm looking for a way to filter fields in REST calls. I'm going to use <a href="https://github.com/bohnman/squiggly-java" rel="nofollow noreferrer">https://github.com/bohnman/squiggly-java</a> but I want to integrate it in Spring resource assembler.</p>
  
  <p>I'm looking for a way to customize the <code>PersistentEntityResourceAssembler</code> that is automatically available in REST controllers.
  This is the code of the class:</p>
  
  <pre><code>public class PersistentEntityResourceAssembler implements ResourceAssembler&lt;Object, PersistentEntityResource&gt; {
      @NonNull
      private final PersistentEntities entities;
      @NonNull
      private final Projector projector;
      @NonNull
      private final Associations associations;
      @NonNull
      private final SelfLinkProvider linkProvider;
      @NonNull
      private final EmbeddedWrappers wrappers = new EmbeddedWrappers(false);
  
      public PersistentEntityResource toResource(Object instance) {
          Assert.notNull(instance, "Entity instance must not be null!");
          return this.wrap(this.projector.projectExcerpt(instance), instance).build();
      }
  
      public PersistentEntityResource toFullResource(Object instance) {
          Assert.notNull(instance, "Entity instance must not be null!");
          return this.wrap(this.projector.project(instance), instance).build();
      }
  
      private Builder wrap(Object instance, Object source) {
          PersistentEntity&lt;?, ?&gt; entity = this.entities.getRequiredPersistentEntity(source.getClass());
          return PersistentEntityResource.build(instance, entity).withEmbedded(this.getEmbeddedResources(source)).withLink(this.getSelfLinkFor(source)).withLink(this.linkProvider.createSelfLinkFor(source));
      }
  
      private Iterable&lt;EmbeddedWrapper&gt; getEmbeddedResources(Object instance) {
          return (new EmbeddedResourcesAssembler(this.entities, this.associations, this.projector)).getEmbeddedResources(instance);
      }
  
      public Link getSelfLinkFor(Object instance) {
          Link link = this.linkProvider.createSelfLinkFor(instance);
          return new Link(link.expand(new Object[0]).getHref(), "self");
      }
  
      public PersistentEntityResourceAssembler(@NonNull PersistentEntities entities, @NonNull Projector projector, @NonNull Associations associations, @NonNull SelfLinkProvider linkProvider) {
          if (entities == null) {
              throw new IllegalArgumentException("entities is marked @NonNull but is null");
          } else if (projector == null) {
              throw new IllegalArgumentException("projector is marked @NonNull but is null");
          } else if (associations == null) {
              throw new IllegalArgumentException("associations is marked @NonNull but is null");
          } else if (linkProvider == null) {
              throw new IllegalArgumentException("linkProvider is marked @NonNull but is null");
          } else {
              this.entities = entities;
              this.projector = projector;
              this.associations = associations;
              this.linkProvider = linkProvider;
          }
      }
  }
  </code></pre>
  
  <p>My guess is that it's injected somewhere into Spring. I want to customize the JSON content dynamically filtering out fields that I don't want.
  I tried to create a copya of the class and annotating it with @Component but it's missing Projector.</p>
  
  <p>What's the right way to customize <code>PersistentEntityResourceAssembler</code> in Spring Data REST?</p>