title: How to save enum field in the database room?
body: <p>I must write the value from the <code>enum</code> enumeration to the database. An error occurs during compilation. What am I doing wrong?</p>
  
  <blockquote>
    <p>Cannot figure out how to save this field into database. You can consider adding a type converter for it.</p>
  </blockquote>
  
  <pre><code>@ColumnInfo(name = "state_of_health")
  @TypeConverters(HealthConverter::class)
  var health: Health
  
  enum class Health(val value: Int){
      NONE(-1),
      VERY_BAD(0),
      ...
  }
  
  class HealthConverter{
  
      @TypeConverter
      fun fromHealth(value: Health): Int{
          return value.ordinal
      }
  
      @TypeConverter
      fun toHealth(value: Int): Health{
          return when(value){
              -1 -&gt; Health.NONE
              0 -&gt; Health.VERY_BAD
              ...
              else -&gt; Health.EXCELLENT
          }
      }
  
  }
  </code></pre>