title: Spring boot rest single path variable which takes different type of values
body: <p>Spring boot rest how to provide an end point which has one path variable which takes different types of values</p>
  
  <pre><code>@Autowired
  private UserRepository userRepository;
  
  @RequestMapping(value="/user/{idOrName}", method=RequestMethod.GET)
  public User findUser(@PathVariable String idOrName) {
    this.userRepository.findByIdOrName(idOrName, idOrName);
  }
  
  public interface UserRepository extends MongoRepository&lt;User, Long&gt; {
    User findByIdOrName(Long id, String name);
  }
  
  @Data
  @Document(collection="user")
  public class User {
    private Long Id;
    private String name;
  }
  </code></pre>
  
  <p><strong>Problem Statement:</strong>
  As you can see from the User model, Id is typeof <code>Long</code> and Name is typeof <code>String</code>. Now I need to implement single end point which offers facility to search user by id or name.</p>
  
  <p>How can I implement rest end point which is having one path variable which either accept id or name which are of different type?</p>
  
  <p>My problem is Not sure how to define <code>@PathVariable</code> when user sends either <code>String</code> or <code>Long</code>. Is it even possible to do? or should I make <code>@PathVariable</code> as <code>String</code> and parse <code>Long</code>?</p>