title: Spring Data Rest: how to register a custom conversionService with custom Converter<Entity, Resource>?
body: <p>There is something that is not enough clear in <a href="http://docs.spring.io/spring-data/rest/docs/current/reference/html/#_customizing_the_representation" rel="noreferrer">this part</a> of Spring Data Rest documentation:</p>
  
  <blockquote>
    <p>The Spring Data REST exporter executes any discovered
    ResourceProcessor`s before it creates the output representation.</p>
  </blockquote>
  
  <p>For what I have noticed, it's true: ResourceProcessor are invoked during the handling of the request, after the completion of RepositoryEntityController respective method.</p>
  
  <blockquote>
    <p>It does this by registering a <code>Converter&lt;Entity, Resource&gt;</code> instance
    with an internal ConversionService.</p>
  </blockquote>
  
  <p>I don't understand when it is used this <code>Converter&lt;Entity,Resource&gt;</code>.</p>
  
  <blockquote>
    <p>This is the component responsible for creating the links to referenced
    entities (e.g. those objects under the _links property in the object’s
    JSON representation). It takes an @Entity and iterates over its
    properties, creating links for those properties that are managed by a
    Repository and copying across any embedded or simple properties.</p>
  </blockquote>
  
  <p>Sure? I noticed that the <strong>_links</strong> to referenced entities are created in the <code>RepositoryEntityController</code>. I didn't see any other component that builds those links: no ConversionService or Converter are involved.</p>
  
  <blockquote>
    <p>If your project needs to have output in a different format, however,
    it’s possible to completely replace the default outgoing JSON
    representation with your own.  If you register your own
    ConversionService in the ApplicationContext and register your own
    Converter, then you can return a Resource
    implementation of your choosing.</p>
  </blockquote>
  
  <p>I don't undestand how is possible to do that.</p>
  
  <p>I have tried to do exactly what is written in the documentation: I have registered my own ConversionService in the ApplicationContext and my own Converter.</p>
  
  <p>I have registered the ConversionService in a custom class that extends RepositoryRestMvcConfiguration:</p>
  
  <pre><code>@Configuration
  public class RepositoryConfiguration extends RepositoryRestMvcConfiguration {
  
      @Autowired
      AuthorConverter authorConverter;
  
      @Bean(name="conversionService")
      public ConversionService getConversionService() {       
          DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
          conversionService.addConverter(authorConverter);
          return conversionService;
      }
  
      @Override
      public DefaultFormattingConversionService defaultConversionService() {
          return (DefaultFormattingConversionService) getConversionService();
      }
  }
  </code></pre>
  
  <p>This is the AuthorConverter:</p>
  
  <pre><code>@Component
  public class AuthorConverter implements Converter&lt;Author, Resource&gt; {
  
      @Override
      public Resource convert(Author source) {
          System.out.println("convert method of class AuthorConverter");
          // still to be implemented
          return null;
      }
  
  }
  </code></pre>
  
  <p>But the converter is never used: if I go the the <code>/authors</code> url, the JSON is solved as the standard representation, and the "convert" method of the converter is never invoked.</p>
  
  <p>I want to understand (possibly with a working example) how have a custom converter that's being involved in the process of the output representation.</p>
  
  <p>Thanks.</p>