title: JPA + JSON deserialization
body: <p>I'm quite new to JPA and using Java as backend for REST services, and I'd like to store a JSON into the database, and wanted to check what is the best way to do so. Please let me know in case I'm taking the "long path".</p>
  
  <p>(I'm using Spring)</p>
  
  <p>My data:</p>
  
  <pre><code>{
    frequency: "Week"
    isGoalOrMore: "true"
    name: "Develop"
    targetValue: "5"
    type: "Average"
  }
  </code></pre>
  
  <p>Habit.java</p>
  
  <pre><code>@Entity
  @Table(name = "habits")
  public class Habit {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private long id;
      private String name;
  
      @ManyToOne(fetch = FetchType.EAGER)
      @JoinColumn(name = "id_habit_type")
      private HabitType type;
  
      private boolean isGoalOrMore; //basically means, achieve goal or do more
      private double targetValue;
  
      @ManyToOne(fetch = FetchType.EAGER)
      @JoinColumn(name = "id_frequency")
      private Frequency frequency;
  
      //getters and setters
  }
  </code></pre>
  
  <p>HabitType.java</p>
  
  <pre><code> @Entity
   @Table(name = "habits_type")
   public class HabitType {
  
       @Id
       private Long id;
  
       private String description;
  
   }
  </code></pre>
  
  <p>DB Model (mysql)</p>
  
  <pre><code>habits
    --id
    --name
    --id_frequency
    --id_habit_type
  
  habits_type
    --id
    --description
  </code></pre>
  
  <h1>Problem</h1>
  
  <p>When I try to save this data I receive an error as below:</p>
  
  <pre><code>com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class com.tiperapp.model.HabitType] from String value ('Average'); no single-String constructor/factory method
  </code></pre>
  
  <h2>How can I solve it?</h2>
  
  <p>By reading some topics, one option would be to write a JSON deserializer. Other cases they solved it by fixing their JPA.
  I'd like to know which would be recommend.. can you guys please help me how to deserialize this, the best way ?</p>