title: Java Enums: Instantiate Enum "dynamically" (more like a class constructor) to use with Jackson
body: <p>I have this Enum:</p>
  
  <pre><code>public enum Role {
  
  Manager("manager"),
  Customer("customer");
  
  private String role;
  
  Role(String role){
      this.role = role;
  }
  }
  </code></pre>
  
  <p>And I have this POJO which I get from an Http request (using Jerey and Jackson):</p>
  
  <pre><code>public class UserCredentials {
  
  private String username;
  private String password;
  private Role role;
  
  public UserCredentials() {
  }
  
  public String getUsername() {
      return username;
  }
  
  public void setUsername(String username) {
      this.username = username;
  }
  
  public String getPassword() {
      return password;
  }
  
  public void setPassword(String password) {
      this.password = password;
  }
  
  public Role getRole() {
      return role;
  }
  
  public void setRole(Role role) {
      this.role = role;
  }
  }
  </code></pre>
  
  <p>The last setter creates an error as Jackson don't really knows how to convert </p>
  
  <pre><code>{
  "username": "shikloshi",
  "password": "password",
  "role": "admin"
  }
  </code></pre>
  
  <p>To an object (specifially the "role" Enum).</p>
  
  <p>I was trying to change the setter to:</p>
  
  <pre><code>public void setRole(String role) {
  this.role = new Role(role);
  }
  </code></pre>
  
  <p>which cannot be done.</p>
  
  <p>Is there a way to invoke enum constructor (or any other way of creation - Jackson for instance) in a more Object Oriented manner (the alternative is to use a switch-case inside the setter)?</p>