title: Kotlin - java.lang.IllegalStateExpection: Expected BEGIN_ARRAY but was STRING
body: <p>I faced with this problem. I've searched in the internet but answers was for Java, not Kotlin. How do i solve this ? If you need anything else please let me know. I'm trying to get closest restaurants for user location. Currently I'm using static variables because I couldn't get Zomato APi yet. How can i manage to do this ? It's been 4-5 days since I start learning kotlin</p>
  <p>My restaurant data class</p>
  <pre><code>data class Restaurant(
      @SerializedName(&quot;name&quot;)
      val restName: String?,
      @SerializedName(&quot;address&quot;)
      val restAddress: String?
  )
  </code></pre>
  <p>My API interface</p>
  <pre><code>interface ZomatoAPI {
  
      @Headers(
          &quot;Accept: application/json&quot;,
          &quot;user-key: $API_KEY&quot;
      )
      @GET(&quot;/search&quot;)
      fun getRestaurants(@Query(&quot;count&quot;) count: Int
                         ,@Query(&quot;lat&quot;) latitude: Double
                         ,@Query(&quot;lon&quot;) longitude: Double
                          ,@Query(&quot;sort&quot;) sort : String
                          ,@Query(&quot;order&quot;) order : String
  
      ): Single&lt;List&lt;Restaurant&gt;&gt;
  
  }
  </code></pre>
  <p>My Service Class</p>
  <pre><code>class RestaurantService{
  
      private val baseUrl = &quot;https://developers.zomato.com/api/v2.1/&quot;
      private val api: ZomatoAPI
      private val latitude = 41.2
      private val longitude = 28.2
  
      init {
  
  
          api = Retrofit.Builder()
              .baseUrl(baseUrl)
              .addConverterFactory(GsonConverterFactory.create(GsonBuilder().setLenient().create()))
              .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
              .build()
              .create(ZomatoAPI::class.java)
      }
  
      fun getRestaurants(): Single&lt;List&lt;Restaurant&gt;&gt;{
          return api.getRestaurants(5,latitude,longitude,&quot;rating&quot;,&quot;desc&quot;)
      }
  
  }
  </code></pre>
  <p>My ListViewModel</p>
  <pre><code>class ListViewModel: ViewModel(){
  
      private val restaurantService = RestaurantService()
      private val disposable = CompositeDisposable()
  
      val restaurants = MutableLiveData&lt;List&lt;Restaurant&gt;&gt;()
      val restaurantLoadError = MutableLiveData&lt;Boolean&gt;()
      val loading = MutableLiveData&lt;Boolean&gt;()
  
      fun refresh() {
          fetchRestaurants()
      }
  
      private fun fetchRestaurants() {
          loading.value = true
  
          restaurantService.getRestaurants()
                  .subscribeOn(Schedulers.newThread())
                  .observeOn(AndroidSchedulers.mainThread())
  
                  .subscribeWith(object: DisposableSingleObserver&lt;List&lt;Restaurant&gt;&gt;(){
                      override fun onSuccess(value: List&lt;Restaurant&gt;?) {
                          restaurants.value = value
                          restaurantLoadError.value = false
                          loading.value = false
                      }
  
                      override fun onError(e: Throwable?) {
                          restaurantLoadError.value = true
                          loading.value = false
                      }
  
                  })
  
      }
  
      override fun onCleared() {
          super.onCleared()
          disposable.clear()
      }
  
  }
  </code></pre>
  <p>Response Body of Zomato API</p>
  <pre><code>{
    &quot;results_found&quot;: 1499579,
    &quot;results_start&quot;: 0,
    &quot;results_shown&quot;: 2,
    &quot;restaurants&quot;: [
      {
        &quot;restaurant&quot;: {
          &quot;R&quot;: {
            &quot;has_menu_status&quot;: {
              &quot;delivery&quot;: -1,
              &quot;takeaway&quot;: -1
            },
            &quot;res_id&quot;: 18047914,
            &quot;is_grocery_store&quot;: false
          },
          &quot;apikey&quot;: &quot;61528551ffc800703d600cb2c25e6900&quot;,
          &quot;id&quot;: &quot;18047914&quot;,
          &quot;name&quot;: &quot;The Mossy Cafe&quot;,
          &quot;url&quot;: &quot;https://www.zomato.com/mossy-point-nsw/the-mossy-cafe-mossy-point?utm_source=api_basic_user&amp;utm_medium=api&amp;utm_campaign=v2.1&quot;,
          &quot;location&quot;: {
            &quot;address&quot;: &quot;31 Pacific Street, Mossy Point&quot;,
            &quot;locality&quot;: &quot;Mossy Point&quot;,
            &quot;city&quot;: &quot;Mossy Point&quot;,
            &quot;city_id&quot;: 2181,
            &quot;latitude&quot;: &quot;-35.8369730000&quot;,
            &quot;longitude&quot;: &quot;150.1796610000&quot;,
            &quot;zipcode&quot;: &quot;&quot;,
            &quot;country_id&quot;: 14,
            &quot;locality_verbose&quot;: &quot;Mossy Point, Mossy Point&quot;
          },
          &quot;switch_to_order_menu&quot;: 0,
          &quot;cuisines&quot;: &quot;Cafe Food, Coffee and Tea&quot;,
          &quot;timings&quot;: &quot;7:30am – 3pm (Mon-Sun)&quot;,
          &quot;average_cost_for_two&quot;: 50,
          &quot;price_range&quot;: 4,
          &quot;currency&quot;: &quot;$&quot;,
          &quot;highlights&quot;: [
            &quot;Cash&quot;,
            &quot;Debit Card&quot;,
            &quot;No Alcohol Available&quot;,
            &quot;Credit Card&quot;,
            &quot;Breakfast&quot;,
            &quot;Lunch&quot;,
            &quot;Kid Friendly&quot;,
            &quot;Vegan Options&quot;,
            &quot;Pet Friendly&quot;,
            &quot;Indoor Seating&quot;,
            &quot;Gluten Free Options&quot;
          ],
          &quot;offers&quot;: [],
          &quot;opentable_support&quot;: 0,
          &quot;is_zomato_book_res&quot;: 0,
          &quot;mezzo_provider&quot;: &quot;OTHER&quot;,
          &quot;is_book_form_web_view&quot;: 0,
          &quot;book_form_web_view_url&quot;: &quot;&quot;,
          &quot;book_again_url&quot;: &quot;&quot;,
          &quot;thumb&quot;: &quot;&quot;,
          &quot;user_rating&quot;: {
            &quot;aggregate_rating&quot;: &quot;3.9&quot;,
            &quot;rating_text&quot;: &quot;Good&quot;,
            &quot;rating_color&quot;: &quot;9ACD32&quot;,
            &quot;rating_obj&quot;: {
              &quot;title&quot;: {
                &quot;text&quot;: &quot;3.9&quot;
              },
              &quot;bg_color&quot;: {
                &quot;type&quot;: &quot;lime&quot;,
                &quot;tint&quot;: &quot;600&quot;
              }
            },
            &quot;votes&quot;: 7
          },
          &quot;all_reviews_count&quot;: 0,
          &quot;photos_url&quot;: &quot;https://www.zomato.com/mossy-point-nsw/the-mossy-cafe-mossy-point/photos?utm_source=api_basic_user&amp;utm_medium=api&amp;utm_campaign=v2.1#tabtop&quot;,
          &quot;photo_count&quot;: 42,
          &quot;menu_url&quot;: &quot;https://www.zomato.com/mossy-point-nsw/the-mossy-cafe-mossy-point/menu?utm_source=api_basic_user&amp;utm_medium=api&amp;utm_campaign=v2.1&amp;openSwipeBox=menu&amp;showMinimal=1#tabtop&quot;,
          &quot;featured_image&quot;: &quot;&quot;,
          &quot;has_online_delivery&quot;: 0,
          &quot;is_delivering_now&quot;: 0,
          &quot;store_type&quot;: &quot;&quot;,
          &quot;include_bogo_offers&quot;: true,
          &quot;deeplink&quot;: &quot;zomato://restaurant/18047914&quot;,
          &quot;is_table_reservation_supported&quot;: 0,
          &quot;has_table_booking&quot;: 0,
          &quot;events_url&quot;: &quot;https://www.zomato.com/mossy-point-nsw/the-mossy-cafe-mossy-point/events#tabtop?utm_source=api_basic_user&amp;utm_medium=api&amp;utm_campaign=v2.1&quot;,
          &quot;phone_numbers&quot;: &quot;02 4471 8599&quot;,
          &quot;all_reviews&quot;: {
            &quot;reviews&quot;: []
          },
          &quot;establishment&quot;: [
            &quot;Café&quot;
          ],
          &quot;establishment_types&quot;: []
        }
      },
      {
        &quot;restaurant&quot;: {
          &quot;R&quot;: {
            &quot;has_menu_status&quot;: {
              &quot;delivery&quot;: -1,
              &quot;takeaway&quot;: -1
            },
            &quot;res_id&quot;: 16611721,
            &quot;is_grocery_store&quot;: false
          },
          &quot;apikey&quot;: &quot;61528551ffc800703d600cb2c25e6900&quot;,
          &quot;id&quot;: &quot;16611721&quot;,
          &quot;name&quot;: &quot;Blue Swimmer at Seahaven&quot;,
          &quot;url&quot;: &quot;https://www.zomato.com/gerroa-nsw/blue-swimmer-at-seahaven-gerroa?utm_source=api_basic_user&amp;utm_medium=api&amp;utm_campaign=v2.1&quot;,
          &quot;location&quot;: {
            &quot;address&quot;: &quot;19 Riverleigh Ave, Gerroa, Gerroa&quot;,
            &quot;locality&quot;: &quot;Gerroa&quot;,
            &quot;city&quot;: &quot;Gerroa&quot;,
            &quot;city_id&quot;: 2154,
            &quot;latitude&quot;: &quot;-34.7697390000&quot;,
            &quot;longitude&quot;: &quot;150.8117400000&quot;,
            &quot;zipcode&quot;: &quot;2534&quot;,
            &quot;country_id&quot;: 14,
            &quot;locality_verbose&quot;: &quot;Gerroa, Gerroa&quot;
          },
          &quot;switch_to_order_menu&quot;: 0,
          &quot;cuisines&quot;: &quot;Modern Australian, Australian&quot;,
          &quot;timings&quot;: &quot;7 AM to 3 PM (Mon, Tue, Wed, Thu, Sun), 7 AM to 3 PM, 5:30 PM to 11 PM (Fri-Sat)&quot;,
          &quot;average_cost_for_two&quot;: 20,
          &quot;price_range&quot;: 2,
          &quot;currency&quot;: &quot;$&quot;,
          &quot;highlights&quot;: [
            &quot;Cash&quot;,
            &quot;Breakfast&quot;,
            &quot;Lunch&quot;,
            &quot;No Alcohol Available&quot;,
            &quot;Dinner&quot;,
            &quot;Table booking recommended&quot;,
            &quot;Outdoor Seating&quot;
          ],
          &quot;offers&quot;: [],
          &quot;opentable_support&quot;: 0,
          &quot;is_zomato_book_res&quot;: 0,
          &quot;mezzo_provider&quot;: &quot;OTHER&quot;,
          &quot;is_book_form_web_view&quot;: 0,
          &quot;book_form_web_view_url&quot;: &quot;&quot;,
          &quot;book_again_url&quot;: &quot;&quot;,
          &quot;thumb&quot;: &quot;&quot;,
          &quot;user_rating&quot;: {
            &quot;aggregate_rating&quot;: &quot;3.9&quot;,
            &quot;rating_text&quot;: &quot;Good&quot;,
            &quot;rating_color&quot;: &quot;9ACD32&quot;,
            &quot;rating_obj&quot;: {
              &quot;title&quot;: {
                &quot;text&quot;: &quot;3.9&quot;
              },
              &quot;bg_color&quot;: {
                &quot;type&quot;: &quot;lime&quot;,
                &quot;tint&quot;: &quot;600&quot;
              }
            },
            &quot;votes&quot;: 21
          },
          &quot;all_reviews_count&quot;: 11,
          &quot;photos_url&quot;: &quot;https://www.zomato.com/gerroa-nsw/blue-swimmer-at-seahaven-gerroa/photos?utm_source=api_basic_user&amp;utm_medium=api&amp;utm_campaign=v2.1#tabtop&quot;,
          &quot;photo_count&quot;: 15,
          &quot;menu_url&quot;: &quot;https://www.zomato.com/gerroa-nsw/blue-swimmer-at-seahaven-gerroa/menu?utm_source=api_basic_user&amp;utm_medium=api&amp;utm_campaign=v2.1&amp;openSwipeBox=menu&amp;showMinimal=1#tabtop&quot;,
          &quot;featured_image&quot;: &quot;&quot;,
          &quot;has_online_delivery&quot;: 0,
          &quot;is_delivering_now&quot;: 0,
          &quot;store_type&quot;: &quot;&quot;,
          &quot;include_bogo_offers&quot;: true,
          &quot;deeplink&quot;: &quot;zomato://restaurant/16611721&quot;,
          &quot;is_table_reservation_supported&quot;: 0,
          &quot;has_table_booking&quot;: 0,
          &quot;events_url&quot;: &quot;https://www.zomato.com/gerroa-nsw/blue-swimmer-at-seahaven-gerroa/events#tabtop?utm_source=api_basic_user&amp;utm_medium=api&amp;utm_campaign=v2.1&quot;,
          &quot;phone_numbers&quot;: &quot;(02) 4234 3796&quot;,
          &quot;all_reviews&quot;: {
            &quot;reviews&quot;: [
              {
                &quot;review&quot;: []
              },
              {
                &quot;review&quot;: []
              },
              {
                &quot;review&quot;: []
              },
              {
                &quot;review&quot;: []
              },
              {
                &quot;review&quot;: []
              }
            ]
          },
          &quot;establishment&quot;: [
            &quot;Casual Dining&quot;
          ],
          &quot;establishment_types&quot;: []
        }
      }
    ]
  }
  </code></pre>