title: Spring Data Rest Adding Link to Root - RepositoryLinksResource cannot be cast to Resource
body: <p>I'm trying to add a custom link to my API's root document, following this answer:
  <a href="https://stackoverflow.com/questions/25783487/custom-response-for-root-request-int-the-spring-rest-hateoas-with-both-repositor?noredirect=1&amp;lq=1">Custom response for root request int the Spring REST HATEOAS with both RepositoryRestResource-s and regular controllers</a></p>
  
  <p>This is my custom resource processor: </p>
  
  <pre><code>import org.springframework.data.rest.webmvc.RepositoryLinksResource;
  import org.springframework.hateoas.Link;
  import org.springframework.hateoas.ResourceProcessor;
  import org.springframework.hateoas.mvc.ControllerLinkBuilder;
  import org.springframework.stereotype.Component;
  
  @Component
  public class CustomRootLinksResourceProcessor implements ResourceProcessor&lt;RepositoryLinksResource&gt; {
  
      @Override
      public RepositoryLinksResource process(RepositoryLinksResource resource) {
           Link link = ControllerLinkBuilder
                  .linkTo(ControllerLinkBuilder
                          .methodOn(CustomerController.class)
                          .register(null))
                  .withRel("registerCustomer");
  
          resource.add(link);
  
          return resource;
      }
  }
  </code></pre>
  
  <p>However, when I query my API I receive the following exception</p>
  
  <pre><code>LOGBACK:19:01:03.425 [http-nio-8080-exec-2] ERROR o.s.d.r.w.RepositoryRestExceptionHandler - org.springframework.data.rest.webmvc.RepositoryLinksResource cannot be cast to org.springframework.hateoas.Resource
  java.lang.ClassCastException: org.springframework.data.rest.webmvc.RepositoryLinksResource cannot be cast to org.springframework.hateoas.Resource
      at org.springframework.hateoas.mvc.ResourceProcessorInvoker$DefaultProcessorWrapper.invokeProcessor(ResourceProcessorInvoker.java:224)
      at org.springframework.hateoas.mvc.ResourceProcessorInvoker.invokeProcessorsFor(ResourceProcessorInvoker.java:141)
      at org.springframework.hateoas.mvc.ResourceProcessorInvoker.invokeProcessorsFor(ResourceProcessorInvoker.java:124)
      at org.springframework.hateoas.mvc.ResourceProcessorHandlerMethodReturnValueHandler.handleReturnValue(ResourceProcessorHandlerMethodReturnValueHandler.java:113)
      at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:81)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:132)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
      at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
  </code></pre>
  
  <p>I'm not sure what I'm doing wrong here, as checking the source code the of ResourceProcessorInvoker it appears there's only a cast to <code>ResourceSupport</code> (which <code>RepositoryLinksResource</code> extends, so it should be fine). Is this a bug in spring data rest or is there something wrong with my <code>CustomRootLinksResourceProcessor</code>?</p>
  
  <pre><code>    @Override
      @SuppressWarnings("unchecked")
      public Object invokeProcessor(Object object) {
          return ((ResourceProcessor&lt;ResourceSupport&gt;) processor).process((ResourceSupport) object);
      }
  </code></pre>