title: The problem is: Expected BEGIN_ARRAY but was BEGIN_OBJECT
body: <p>my problem is kinda common. After checking tons of resources i still cant find any solutions.
  In some cases people saying to use List of models, instead of models. But the problem existed with List of models. In this case i work with MVVM pattern.
  Let me show.</p>
  <p><em>Asnwer which i will get if example word: policeman</em></p>
  <pre class="lang-json prettyprint-override"><code>{&quot;head&quot;:{},&quot;def&quot;:[{&quot;text&quot;:&quot;lawman&quot;,&quot;pos&quot;:&quot;noun&quot;,&quot;ts&quot;:&quot;lɔːmæn&quot;,&quot;tr&quot;:[{&quot;text&quot;:&quot;officer&quot;,&quot;pos&quot;:&quot;noun&quot;,&quot;fr&quot;:1,&quot;syn&quot;:[{&quot;text&quot;:&quot;policeman&quot;,&quot;pos&quot;:&quot;noun&quot;,&quot;fr&quot;:1}]}]}]}
  </code></pre>
  <p>The API looks like a dictionary, which return similar words when user typing a word</p>
  <p>In code im only need to get these similar words and show it.</p>
  <p>Model class</p>
  <pre class="lang-kotlin prettyprint-override"><code>data class DictModel(
      val text : String
  )
  </code></pre>
  <p>Api Object</p>
  <pre class="lang-kotlin prettyprint-override"><code>object DictApiObject {
      private val retrofit by lazy {
          Retrofit.Builder()
              .baseUrl(&quot;https://dictionary.yandex.net/api/v1/dicservice.json/&quot;)
              .addConverterFactory(GsonConverterFactory.create())
              .build()
      }
      val api : DictAPI by lazy {
          retrofit.create(DictAPI::class.java)
      }
  }
  </code></pre>
  <p>Api interface</p>
  <pre class="lang-kotlin prettyprint-override"><code>interface DictAPI {
  
      @GET(&quot;lookup&quot;)
      suspend fun getTextFromDictApi(
          @Query(&quot;key&quot;) apiKey : String,
          @Query(&quot;lang&quot;) lang : String,
          @Query(&quot;text&quot;) text : String
          ): Response&lt;List&lt;DictModel&gt;&gt;
  
  }
  </code></pre>
  <p>Repository method</p>
  <pre class="lang-kotlin prettyprint-override"><code>    suspend fun getTextFromApi(apiKey : String, lang : String, text:String) : Response&lt;List&lt;DictModel&gt;&gt; {
          return DictApiObject.api.getTextFromDictApi(apiKey, lang, text)
      }
  </code></pre>
  <p>ViewModel var, method, factory</p>
  <pre class="lang-kotlin prettyprint-override"><code>    var myResponse: MutableLiveData&lt;Response&lt;List&lt;DictModel&gt;&gt;&gt; = MutableLiveData()
  
      fun getTextApi(apiKey : String, lang : String, text:String) {
          viewModelScope.launch{
              val response = cardRepository.getTextFromApi(apiKey, lang, text)
              myResponse.value = response
          }
      }
  
      class CardViewModelFactory(private val application: Application) : ViewModelProvider.Factory {
          override fun &lt;T : ViewModel&gt; create(modelClass: Class&lt;T&gt;): T {
              @Suppress(&quot;UNCHECKED_CAST&quot;)
              if (modelClass.isAssignableFrom(CardViewModel::class.java)) {
                  return CardViewModel(application) as T
              }
              throw IllegalArgumentException(&quot;Unknown ViewModel class&quot;)
          }
      }
  </code></pre>
  <p>Main activity with viewmodel init and calling view model</p>
  <pre class="lang-kotlin prettyprint-override"><code>val viewModel = ViewModelProvider(this).get(CardViewModel::class.java)
  viewModel.getTextApi(&quot;my-api-key&quot;, &quot;en-en&quot;, &quot;policeman&quot;)
  viewModel.myResponse.observe(this, Observer { response -&gt;
         if(response.isSuccessful) {
               response.body()?.forEach {
                      Log.e(&quot;Response&quot;, it.text)
               }
          }else{
               Log.e(&quot;Response&quot;, &quot;CANNOT_LOAD_DATA&quot;)
  }
  </code></pre>
  <p>And error code</p>
  <pre><code>    java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
          at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:350)
          at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:80)
          at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
          at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:39)
          at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:27)
          at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:225)
          at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:121)
          at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
          at java.lang.Thread.run(Thread.java:923)
          Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@c4dedaa, Dispatchers.Main.immediate]
  </code></pre>