title: How to serialize/deserialize Kotlin enum class with constructor to json
body: <p>I am trying to save an enum class to Room db. My class is;</p>
  
  <pre><code>enum class TestClass(val firstField: String, secondField: Long) {
      FIRST("test", 1L),
      SECOND("test_2", 2L),
      THIRD("test_3", 3L)
  }
  </code></pre>
  
  <p>My TypeConverters are;</p>
  
  <pre><code>    @TypeConverter
      fun jsonToTestClassList(json: String) = Gson().fromJson&lt;MutableSet&lt;TestClass&gt;&gt;(json)
  
      @TypeConverter
      fun testClassToJson(testClassSet: MutableSet&lt;TestClass&gt;?) = Gson().toJson(testClassSet)
  </code></pre>
  
  <p>When I save it to room, it shows only enums, not enum's constructors. For example, if list has 2 enums, it saves like</p>
  
  <pre><code>["FIRST", "SECOND"]
  </code></pre>
  
  <p>How can I achieve to serialize and deserialize to keep constructor parameters like,</p>
  
  <pre><code>[{FIRST, "test", 1L}, {SECOND, "test_2", 2L}]
  </code></pre>
  
  <p>Or something like that to get constructor parameters back. </p>
  
  <p><strong>UPDATE:</strong> </p>
  
  <p>I've figure it out; I just created new class and in TypeConverter I converted my enum to class that new class I've just created. </p>
  
  <pre><code>
      @TypeConverter
      fun jsonToTestClassList(json: String): MutableSet&lt;TestClass&gt;? {
          return Gson().fromJson&lt;List&lt;TestClassDatabase&gt;?&gt;(json)?.map {
              it.testClass.apply {
                  firstField = it.firstField
              }
          }?.toMutableSet()
      }
  
      @TypeConverter
      fun testClassToJson(testClassList: MutableSet&lt;TestClass&gt;?): String {
          return Gson().toJson(testClassList?.run {
              mutableListOf&lt;TestClassDatabase&gt;().apply {
                  addAll(testClassList.map {
                      TestClassDatabase(it, it.firstField)
                  })
              }
          })
      }
  </code></pre>
  
  <p>Not my proudest code tho, but you get the point.</p>