title: Accepting a Spring Data REST URI in custom controller
body: <p>I have a Spring Data Rest webmvc application that I'd like to add some custom functionality to for batch operations.</p>
  
  <p>I've created a controller, and blended it into the uri namespace, but I'd like for it to be able to accept URI's like the custom <code>/search</code> queries do, rather than simply an ID.</p>
  
  <p>I have tried registering a custom <code>&lt;String, Long&gt;</code> converter (my entity has a <code>Long</code> ID type, but that seems to get ignored. Is there any way to configure my controller such that it adopts that behavior from the auto-implemented SDR controllers?</p>
  
  <p>Even if there is some sort of method I can call that will auto-resolve a URI to an entity, that would work just as well (as I can then simply accept a <code>String</code> in my controller)</p>
  
  <p>Here's where I'm at.</p>
  
  <pre><code>@Configuration
  public class CustomWebConfiguration extends WebMvcConfigurationSupport {
  
      //irrelevant code omitted
  
      @Bean
      public DomainClassConverter&lt;?&gt; domainClassConverter() {
          DomainClassConverter&lt;FormattingConversionService&gt; dc = new DomainClassConverter&lt;FormattingConversionService&gt;(mvcConversionService());
          return dc;
      }
  
      @Override
      public void addFormatters(FormatterRegistry registry) {
            registry.addConverter(String.class, Long.class, testConverter());
      }
  
      @Bean 
      Converter&lt;String, Long&gt; testConverter() {
          return new Converter&lt;String, Long&gt;() {
  
              @Override
              public Long convert(String source) {
                  //this code does _not_ get run at any point
                  if (source.indexOf('/') == -1) { return Long.parseLong(source); }
  
                  source = source.substring(source.lastIndexOf('/') + 1);
                  Long id = Long.parseLong(source);
  
                  return id;
              }   
          };
      }
  }
  </code></pre>
  
  <p>SDR Config</p>
  
  <pre><code>@Configuration
  @EnableHypermediaSupport(type = { HypermediaType.HAL })
  public class CustomRestConfiguration extends RepositoryRestMvcConfiguration {
  
      @Override
      public RepositoryRestConfiguration config() {
        RepositoryRestConfiguration config = super.config();
        config.setBasePath("/api");
        config.exposeIdsFor(ApplicationMembership.class);
        return config;
      }
  
  
  }
  </code></pre>
  
  <p>And my (contrived) controller:</p>
  
  <p>ApplicationType is one of my entities that are correctly managed by SDR/repository magic</p>
  
  <pre><code>@BasePathAwareController
  @RepositoryRestController
  @RequestMapping("applications/special")
  public class ApplicationExtensionController {
      @RequestMapping("a")
      public ResponseEntity&lt;?&gt; reply(@RequestParam("type") ApplicationType type) {
          return new ResponseEntity&lt;String&gt;(type.getIcon(), HttpStatus.OK);
      }
  }
  </code></pre>
  
  <p>I've looked around quite a bit but can't quite manage to make anything work. When I create a <code>&lt;String, ApplicationType&gt;</code> converter that utilizes the repository, it also does not get called, as the DomainClassConverter just calls its underlying <code>&lt;String, Long&gt;</code> converter (which obviously fails, as it cannot correctly parse out <code>types/1</code> into a long.</p>
  
  <p>Appreciate the help!</p>
  
  <p>Forgot to mention</p>
  
  <ul>
  <li>Spring Data Rest 2.4.0</li>
  <li>Spring HATEOAS 0.19.0</li>
  <li>Spring 4.2.1</li>
  </ul>
  
  <p>Using JPA repositories</p>