title: How to create a right JSON class in Kotlin (for Fuel)
body: <p>I have a request that returns JSON:</p>
  
  <pre><code>{
    "success": 0,
    "errors": {
      "phone": [
        "Incorrect phone number"
      ]
    }
  }
  </code></pre>
  
  <p>I plugged Fuel instead of Retrofit for Kotlin. So, my classes are:</p>
  
  <pre><code>data class RegistrationResponse(
      val success: Int,
      val errors: RegistrationErrorsResponse?) {
  
      class Deserializer : ResponseDeserializable&lt;RegistrationResponse&gt; {
          override fun deserialize(content: String): RegistrationResponse? =
              Gson().fromJson(content, RegistrationResponse::class.java)
      }
  }
  
  data class RegistrationErrorsResponse(val phone: List&lt;String&gt;?) {
  
      class Deserializer : ResponseDeserializable&lt;RegistrationErrorsResponse&gt; {
          override fun deserialize(content: String): RegistrationErrorsResponse? =
              Gson().fromJson(content, RegistrationErrorsResponse::class.java)
      }
  }
  </code></pre>
  
  <p>A request looks like:</p>
  
  <pre><code>class Api {
  
      init {
          FuelManager.instance.basePath = SERVER_URL
      }
  
      fun registration(name: String, phone: String): Request =
          "/registration/"
              .httpPost(listOf("name" to name, "phone" to phone))
  }
  
  private fun register(name: String, phone: String) {
      Api().registration(name, phone)
          .responseObject(RegistrationResponse.Deserializer()) { _, response, result -&gt;
              val registrationResponse = result.component1()
              if (registrationResponse?.success == 1) {
                  showScreen()
              } else {
                  showErrorDialog(registrationResponse?.errors?.phone?.firstOrNull())
              }
          }
  }
  </code></pre>
  
  <p>A problem is that when error occurs, <code>phone</code> variable in data class (registrationResponse?.errors?.phone) is filled with <code>null</code>, but not "Incorrect phone number".</p>