title: How to get GSON & Retrofit to serialize and map an array from a JSON response into a String?
body: <p>I am making an API request which returns some array values. I need to serialize these array values so that I can assign them to their corresponding class attributes (which are String types). </p>
  
  <p>Now I know how to use GSON to serialize and deserialize lists, but with Retrofit the mapping is done automatically. This means that if my attribute is of type String, the API call returns the error "Expected a String but received an Array instead". How do I get around this so that I can receive them as arrays without failure, and them store them as strings subsequently?</p>
  
  <p>My API Response:</p>
  
  <pre><code>{
  "utterances": [{
          "langs": ["eng", "afr", "xho", "zul"],
          "utts": [
              "Have you been here before?",
              "Was u al hier gewees?",
              "Ingaba wakhe weza apha ngaphambili?",
              "Ingabe uke weza lapha ngaphambilini?"
          ],
          "responses": [
              ["Yes", "No"],
              ["Ja", "Nee"],
              ["Ewe", "Hayi"],
              ["Yebo", "Cha"]
          ]
      },
      {
          "langs": ["eng", "afr", "xho", "zul"],
          "utts": [
              "How are you?",
              "Hoe gaan dit met jou?",
              "unjani?",
              "unjani?"
          ],
          "responses": [
              ["Good", "Bad"],
              ["Goed", "sleg"],
              ["ezilungileyo", "ezimbi"],
              ["kuhle", "kubi"]
          ]
      }
  ]
  }
  </code></pre>
  
  <p>My UtteranceResponse class:</p>
  
  <pre><code>class UtteranceResponse {
  
  @SerializedName("status")
  var status: String? = null
  
  @SerializedName("count")
  var count: Int = 0
  
  @SerializedName("utterances")
  var utterances: ArrayList&lt;Utterance&gt;? = null
  }
  </code></pre>
  
  <p>My Utterance class:</p>
  
  <pre><code>class Utterance: SugarRecord {
  
  @SerializedName ("langs")
  var langs: String? = null
  
  @SerializedName ("utts")
  var utterances_text: String? = null
  
  var utterances_tts: String? = null
  
  @SerializedName ("responses")
  var responses_text: String? = null
  
  constructor(){
  
  }
  }
  </code></pre>
  
  <p>And finally the calling function:</p>
  
  <pre><code>    fun getUtterancesFromWebservice (){
      val apiService = ApiInterface.create()
      val call = apiService.getUtteranceDetails()
  
      call.enqueue(object: Callback&lt;UtteranceResponse&gt; {
          override fun onResponse(call: Call&lt;UtteranceResponse&gt;, response: retrofit2.Response&lt;UtteranceResponse&gt;?) {
              if (response != null) {
                  if (response.body()?.utterances != null){
                      var list: List&lt;Utterance&gt; = response.body()?.utterances!!
                      val utterances: Utterance = list[0]
                      //storeUtterancesFromList(list)
                  } else {
                      Log.d ("Response:", response.body().toString())
                  }
              }else{
                  Log.d ("responseResult", "NULL")
              }
  
          }
  
          override fun onFailure(call: Call&lt;UtteranceResponse&gt;, t: Throwable) {
              Log.e("SHIT", t.toString())
  
          }
      })
  }
  </code></pre>
  
  <p><strong>UPDATE</strong>
  My API Interface as well:</p>
  
  <pre><code>@GET("bins/1ahazo")
  abstract fun getUtteranceDetails():Call&lt;UtteranceResponse&gt;
  
      companion object Factory {
          const val BASE_URL = "https://api.myjson.com/"
          fun create(): ApiInterface {
              val gson = GsonBuilder().setPrettyPrinting().create()
              val retrofit = Retrofit.Builder()
                      .baseUrl(BASE_URL)
                      .addConverterFactory(GsonConverterFactory.create())
                      .build()
              return retrofit.create(ApiInterface::class.java)
          }
      }
  </code></pre>