title: Jackson - hibernate entities serialization
body: <p>I want to serialize and deserialize hibernate entities that contains other entities into flat JSON format.
  So let's say I have the following entities:</p>
  
  <p>Key:</p>
  
  <pre><code>@Entity
  public class Key implements Serializable{
  
  private static final long serialVersionUID = 1L;
  
  @Id
  @Column(name = "KeyID")
  private Long id;
  
  @Column
  private String description;
  
  @ManyToOne(cascade = CascadeType.ALL)
  @JoinColumn(name = "KeyTypeID", nullable = false)
  private KeyType keyType;
  
  public Long getId() {
      return id;
  }
  
  public String getDescription() {
      return description;
  }
  
  public void setDescription(String description) {
      this.description = description;
  }
  
  public KeyType getKeyType() {
      return keyType;
  }
  
  public void setKeyType(KeyType keyType) {
      this.keyType = keyType;
  }
  }
  </code></pre>
  
  <p>KeyType:</p>
  
  <pre><code>@Entity
  public class KeyType implements Serializable {
  
  private static final long serialVersionUID = 1L;
  
  @Id
  @Column(name = "KeyTypeID")
  private Long id;
  
  @Column(name = "Name", nullable = false, unique = true)
  private String name;
  
  public Long getId() {
      return id;
  }
  
  public void setId(Long id) {
      this.id = id;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  }
  </code></pre>
  
  <p>I want to serialize objects of Key class into:</p>
  
  <pre><code>{
      "keyID": 1,    
      "description": "key 1",
      "keyTypeName": "Type 5" //this is Key.keyType.name
  }
  </code></pre>
  
  <p>I also want to be able to deserialize above JSON into Key object containing KeyType entity.
  Is that possible using Jackson or do I need to implement custom code?</p>