Retrofit: D/Response: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $GSON throwing “Expected BEGIN_OBJECT but was BEGIN_ARRAY”?Retrofit Expected BEGIN_OBJECT but was BEGIN_ARRAYRetrofit: Expected BEGIN_OBJECT but was BEGIN_ARRAYRetrofit - MongoDB - Expected BEGIN_ARRAY but was BEGIN_OBJECTRetrofit2 Android: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $Retrofit Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 pathRetrofit: Expected BEGIN_ARRAY but was BEGIN_OBJECTRetrofit 2 “Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $”retrofit error : Expected BEGIN_OBJECT but was BEGIN_ARRAYExpected BEGIN_ARRAY but was BEGIN_OBJECT Android Retrofit

What features enable the Su-25 Frogfoot to operate with such a wide variety of fuels?

How do I fix the group tension caused by my character stealing and possibly killing without provocation?

Does "he squandered his car on drink" sound natural?

How does electrical safety system work on ISS?

How to preserve electronics (computers, iPads and phones) for hundreds of years

Multiplicative persistence

How to get directions in deep space?

Has any country ever had 2 former presidents in jail simultaneously?

Stack Interview Code methods made from class Node and Smart Pointers

How can ping know if my host is down

Pre-mixing cryogenic fuels and using only one fuel tank

How do you make your own symbol when Detexify fails?

Permission on Database

Why does Carol not get rid of the Kree symbol on her suit when she changes its colours?

When were female captains banned from Starfleet?

What is the English pronunciation of "pain au chocolat"?

Mimic lecturing on blackboard, facing audience

Biological Blimps: Propulsion

Can I cause damage to electrical appliances by unplugging them when they are turned on?

What is the highest possible scrabble score for placing a single tile

Do we have to expect a queue for the shuttle from Watford Junction to Harry Potter Studio?

Does grappling negate Mirror Image?

Microchip documentation does not label CAN buss pins on micro controller pinout diagram

How to draw a matrix with arrows in limited space



Retrofit: D/Response: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $


GSON throwing “Expected BEGIN_OBJECT but was BEGIN_ARRAY”?Retrofit Expected BEGIN_OBJECT but was BEGIN_ARRAYRetrofit: Expected BEGIN_OBJECT but was BEGIN_ARRAYRetrofit - MongoDB - Expected BEGIN_ARRAY but was BEGIN_OBJECTRetrofit2 Android: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $Retrofit Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 pathRetrofit: Expected BEGIN_ARRAY but was BEGIN_OBJECTRetrofit 2 “Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $”retrofit error : Expected BEGIN_OBJECT but was BEGIN_ARRAYExpected BEGIN_ARRAY but was BEGIN_OBJECT Android Retrofit













0















I want to get the first "City" object from this JSON response from a URL (or get them all as an array and then use .map() operator in RxJava to get the first city):




totalResultsCount: 5,
names: [

city: stockholm
,

city: oslo
,

city: london
,

city: moscow
,

city: mumbai

]



Here is code responsible for getting this:



public interface MyApi 

@GET("searchJSON?")
Observable<City[]> getPopulation(
@QueryMap Map<String, String> queries
);




and this class



public class MyApiService

private final String baseUrl = "myapiurl";
private MyApi api;
private final Gson gson;
private final OkHttpClient okHttpClient;

public MyApiService()
gson = new Gson();
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
okHttpClient = new OkHttpClient();
okHttpClient.newBuilder().addInterceptor(httpLoggingInterceptor);
buildApi();


private void buildApi()
api = new Retrofit.Builder()
.baseUrl(baseUrl)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build()
.create(MyApi.class);


public Observable<City> getPopulation(String city)
return api
.getPopulation(city)
.map(c -> c[0])
.subscribeOn(Schedulers.io());




When I call getPopulation from an activity, I get this message:




D/Response: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column
2 path $




Here is how my City class looks like:



public class City 

@SerializedName("city")
private String name;

public City(String name)
this.name = name;




Any ideas?



EDIT:



I tried adding a custom deserializer like:



public class MyDeserializer implements JsonDeserializer<City> 

@Override
public City deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
JsonElement cities = json.getAsJsonObject().get("names");
return new Gson().fromJson(cities, City.class);





and changing to:



gson = new GsonBuilder()
.registerTypeAdapter(City.class, new MyDeserializer())
.create();


but I still get the exact same response as earlier.










share|improve this question
























  • Delete my answer because it is Rx question I thougth the problem was JSON, try to add the relevant information using the wrapper class mentioned

    – cutiko
    Mar 8 at 12:07











  • @cutiko your answer was kinda helpful too. I managed to solve this by changing GET method and my getcities method and add some relevant RxJava methods. Thanks for your help.

    – Carlton
    Mar 8 at 12:53











  • Welcomr, post the solution then

    – cutiko
    Mar 8 at 13:29















0















I want to get the first "City" object from this JSON response from a URL (or get them all as an array and then use .map() operator in RxJava to get the first city):




totalResultsCount: 5,
names: [

city: stockholm
,

city: oslo
,

city: london
,

city: moscow
,

city: mumbai

]



Here is code responsible for getting this:



public interface MyApi 

@GET("searchJSON?")
Observable<City[]> getPopulation(
@QueryMap Map<String, String> queries
);




and this class



public class MyApiService

private final String baseUrl = "myapiurl";
private MyApi api;
private final Gson gson;
private final OkHttpClient okHttpClient;

public MyApiService()
gson = new Gson();
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
okHttpClient = new OkHttpClient();
okHttpClient.newBuilder().addInterceptor(httpLoggingInterceptor);
buildApi();


private void buildApi()
api = new Retrofit.Builder()
.baseUrl(baseUrl)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build()
.create(MyApi.class);


public Observable<City> getPopulation(String city)
return api
.getPopulation(city)
.map(c -> c[0])
.subscribeOn(Schedulers.io());




When I call getPopulation from an activity, I get this message:




D/Response: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column
2 path $




Here is how my City class looks like:



public class City 

@SerializedName("city")
private String name;

public City(String name)
this.name = name;




Any ideas?



EDIT:



I tried adding a custom deserializer like:



public class MyDeserializer implements JsonDeserializer<City> 

@Override
public City deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
JsonElement cities = json.getAsJsonObject().get("names");
return new Gson().fromJson(cities, City.class);





and changing to:



gson = new GsonBuilder()
.registerTypeAdapter(City.class, new MyDeserializer())
.create();


but I still get the exact same response as earlier.










share|improve this question
























  • Delete my answer because it is Rx question I thougth the problem was JSON, try to add the relevant information using the wrapper class mentioned

    – cutiko
    Mar 8 at 12:07











  • @cutiko your answer was kinda helpful too. I managed to solve this by changing GET method and my getcities method and add some relevant RxJava methods. Thanks for your help.

    – Carlton
    Mar 8 at 12:53











  • Welcomr, post the solution then

    – cutiko
    Mar 8 at 13:29













0












0








0








I want to get the first "City" object from this JSON response from a URL (or get them all as an array and then use .map() operator in RxJava to get the first city):




totalResultsCount: 5,
names: [

city: stockholm
,

city: oslo
,

city: london
,

city: moscow
,

city: mumbai

]



Here is code responsible for getting this:



public interface MyApi 

@GET("searchJSON?")
Observable<City[]> getPopulation(
@QueryMap Map<String, String> queries
);




and this class



public class MyApiService

private final String baseUrl = "myapiurl";
private MyApi api;
private final Gson gson;
private final OkHttpClient okHttpClient;

public MyApiService()
gson = new Gson();
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
okHttpClient = new OkHttpClient();
okHttpClient.newBuilder().addInterceptor(httpLoggingInterceptor);
buildApi();


private void buildApi()
api = new Retrofit.Builder()
.baseUrl(baseUrl)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build()
.create(MyApi.class);


public Observable<City> getPopulation(String city)
return api
.getPopulation(city)
.map(c -> c[0])
.subscribeOn(Schedulers.io());




When I call getPopulation from an activity, I get this message:




D/Response: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column
2 path $




Here is how my City class looks like:



public class City 

@SerializedName("city")
private String name;

public City(String name)
this.name = name;




Any ideas?



EDIT:



I tried adding a custom deserializer like:



public class MyDeserializer implements JsonDeserializer<City> 

@Override
public City deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
JsonElement cities = json.getAsJsonObject().get("names");
return new Gson().fromJson(cities, City.class);





and changing to:



gson = new GsonBuilder()
.registerTypeAdapter(City.class, new MyDeserializer())
.create();


but I still get the exact same response as earlier.










share|improve this question
















I want to get the first "City" object from this JSON response from a URL (or get them all as an array and then use .map() operator in RxJava to get the first city):




totalResultsCount: 5,
names: [

city: stockholm
,

city: oslo
,

city: london
,

city: moscow
,

city: mumbai

]



Here is code responsible for getting this:



public interface MyApi 

@GET("searchJSON?")
Observable<City[]> getPopulation(
@QueryMap Map<String, String> queries
);




and this class



public class MyApiService

private final String baseUrl = "myapiurl";
private MyApi api;
private final Gson gson;
private final OkHttpClient okHttpClient;

public MyApiService()
gson = new Gson();
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
okHttpClient = new OkHttpClient();
okHttpClient.newBuilder().addInterceptor(httpLoggingInterceptor);
buildApi();


private void buildApi()
api = new Retrofit.Builder()
.baseUrl(baseUrl)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create(gson))
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build()
.create(MyApi.class);


public Observable<City> getPopulation(String city)
return api
.getPopulation(city)
.map(c -> c[0])
.subscribeOn(Schedulers.io());




When I call getPopulation from an activity, I get this message:




D/Response: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column
2 path $




Here is how my City class looks like:



public class City 

@SerializedName("city")
private String name;

public City(String name)
this.name = name;




Any ideas?



EDIT:



I tried adding a custom deserializer like:



public class MyDeserializer implements JsonDeserializer<City> 

@Override
public City deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
JsonElement cities = json.getAsJsonObject().get("names");
return new Gson().fromJson(cities, City.class);





and changing to:



gson = new GsonBuilder()
.registerTypeAdapter(City.class, new MyDeserializer())
.create();


but I still get the exact same response as earlier.







android retrofit rx-java retrofit2 rx-java2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 11:39







Carlton

















asked Mar 7 at 23:42









CarltonCarlton

95321638




95321638












  • Delete my answer because it is Rx question I thougth the problem was JSON, try to add the relevant information using the wrapper class mentioned

    – cutiko
    Mar 8 at 12:07











  • @cutiko your answer was kinda helpful too. I managed to solve this by changing GET method and my getcities method and add some relevant RxJava methods. Thanks for your help.

    – Carlton
    Mar 8 at 12:53











  • Welcomr, post the solution then

    – cutiko
    Mar 8 at 13:29

















  • Delete my answer because it is Rx question I thougth the problem was JSON, try to add the relevant information using the wrapper class mentioned

    – cutiko
    Mar 8 at 12:07











  • @cutiko your answer was kinda helpful too. I managed to solve this by changing GET method and my getcities method and add some relevant RxJava methods. Thanks for your help.

    – Carlton
    Mar 8 at 12:53











  • Welcomr, post the solution then

    – cutiko
    Mar 8 at 13:29
















Delete my answer because it is Rx question I thougth the problem was JSON, try to add the relevant information using the wrapper class mentioned

– cutiko
Mar 8 at 12:07





Delete my answer because it is Rx question I thougth the problem was JSON, try to add the relevant information using the wrapper class mentioned

– cutiko
Mar 8 at 12:07













@cutiko your answer was kinda helpful too. I managed to solve this by changing GET method and my getcities method and add some relevant RxJava methods. Thanks for your help.

– Carlton
Mar 8 at 12:53





@cutiko your answer was kinda helpful too. I managed to solve this by changing GET method and my getcities method and add some relevant RxJava methods. Thanks for your help.

– Carlton
Mar 8 at 12:53













Welcomr, post the solution then

– cutiko
Mar 8 at 13:29





Welcomr, post the solution then

– cutiko
Mar 8 at 13:29












2 Answers
2






active

oldest

votes


















0














Your custom deserializer uses getAsJsonObject("names") but names is a JsonArray in your json response.



names: [] // This is a JsonArray

names: // This is a JsonObject





share|improve this answer


















  • 1





    Any suggestions how i could parse to return city array from my get method?

    – Carlton
    Mar 8 at 11:56


















0














I manage to solve this.



I changed my API calls to:



@GET("searchJSON?")
Observable<ResponseBody> getPopulation(
@QueryMap Map<String, String> queries
);


And I changed my api call method to:



public Observable<City> getPopulation(String city) {
return api
.getPopulation(city)
.map(c -> c.getCities().get(0))
.subscribeOn(Schedulers.io());


And I changed my Serializeble POJOs to:



public class ResponseBody implements Serializable


@SerializedName("totalResultsCount")
@Expose
private int totalResultsCount;
@SerializedName("names")
@Expose
private List<City> cities = null;

public ResponseBody()


public ResponseBody(int totalResultsCount, List<City> cities)
super();
this.totalResultsCount = totalResultsCount;
this.cities = cities;


public int getTotalResultsCount()
return totalResultsCount;


public void setTotalResultsCount(int totalResultsCount)
this.totalResultsCount = totalResultsCount;


public List<City> getCities()
return cities;


public void setNames(List<City> cities)
this.cities = cities;





and



public class City implements Serializable

@SerializedName("name")
@Expose
private String name;

public City()


public City(String name)
super();
this.name = name;


public String getName()
return name;


public void setName(String name)
this.name = name;





And I complete removed the custom Deserializer.



It was a combination of my POJO and Wrong choice of RxJava operations which led to my problem. I hope this answer might help someone in the future.



If anyone have a better solution/way to handle this I would appreciate comments.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054579%2fretrofit-d-response-expected-begin-array-but-was-begin-object-at-line-1-column%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Your custom deserializer uses getAsJsonObject("names") but names is a JsonArray in your json response.



    names: [] // This is a JsonArray

    names: // This is a JsonObject





    share|improve this answer


















    • 1





      Any suggestions how i could parse to return city array from my get method?

      – Carlton
      Mar 8 at 11:56















    0














    Your custom deserializer uses getAsJsonObject("names") but names is a JsonArray in your json response.



    names: [] // This is a JsonArray

    names: // This is a JsonObject





    share|improve this answer


















    • 1





      Any suggestions how i could parse to return city array from my get method?

      – Carlton
      Mar 8 at 11:56













    0












    0








    0







    Your custom deserializer uses getAsJsonObject("names") but names is a JsonArray in your json response.



    names: [] // This is a JsonArray

    names: // This is a JsonObject





    share|improve this answer













    Your custom deserializer uses getAsJsonObject("names") but names is a JsonArray in your json response.



    names: [] // This is a JsonArray

    names: // This is a JsonObject






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 8 at 3:37









    Mauro CurbeloMauro Curbelo

    986




    986







    • 1





      Any suggestions how i could parse to return city array from my get method?

      – Carlton
      Mar 8 at 11:56












    • 1





      Any suggestions how i could parse to return city array from my get method?

      – Carlton
      Mar 8 at 11:56







    1




    1





    Any suggestions how i could parse to return city array from my get method?

    – Carlton
    Mar 8 at 11:56





    Any suggestions how i could parse to return city array from my get method?

    – Carlton
    Mar 8 at 11:56













    0














    I manage to solve this.



    I changed my API calls to:



    @GET("searchJSON?")
    Observable<ResponseBody> getPopulation(
    @QueryMap Map<String, String> queries
    );


    And I changed my api call method to:



    public Observable<City> getPopulation(String city) {
    return api
    .getPopulation(city)
    .map(c -> c.getCities().get(0))
    .subscribeOn(Schedulers.io());


    And I changed my Serializeble POJOs to:



    public class ResponseBody implements Serializable


    @SerializedName("totalResultsCount")
    @Expose
    private int totalResultsCount;
    @SerializedName("names")
    @Expose
    private List<City> cities = null;

    public ResponseBody()


    public ResponseBody(int totalResultsCount, List<City> cities)
    super();
    this.totalResultsCount = totalResultsCount;
    this.cities = cities;


    public int getTotalResultsCount()
    return totalResultsCount;


    public void setTotalResultsCount(int totalResultsCount)
    this.totalResultsCount = totalResultsCount;


    public List<City> getCities()
    return cities;


    public void setNames(List<City> cities)
    this.cities = cities;





    and



    public class City implements Serializable

    @SerializedName("name")
    @Expose
    private String name;

    public City()


    public City(String name)
    super();
    this.name = name;


    public String getName()
    return name;


    public void setName(String name)
    this.name = name;





    And I complete removed the custom Deserializer.



    It was a combination of my POJO and Wrong choice of RxJava operations which led to my problem. I hope this answer might help someone in the future.



    If anyone have a better solution/way to handle this I would appreciate comments.






    share|improve this answer



























      0














      I manage to solve this.



      I changed my API calls to:



      @GET("searchJSON?")
      Observable<ResponseBody> getPopulation(
      @QueryMap Map<String, String> queries
      );


      And I changed my api call method to:



      public Observable<City> getPopulation(String city) {
      return api
      .getPopulation(city)
      .map(c -> c.getCities().get(0))
      .subscribeOn(Schedulers.io());


      And I changed my Serializeble POJOs to:



      public class ResponseBody implements Serializable


      @SerializedName("totalResultsCount")
      @Expose
      private int totalResultsCount;
      @SerializedName("names")
      @Expose
      private List<City> cities = null;

      public ResponseBody()


      public ResponseBody(int totalResultsCount, List<City> cities)
      super();
      this.totalResultsCount = totalResultsCount;
      this.cities = cities;


      public int getTotalResultsCount()
      return totalResultsCount;


      public void setTotalResultsCount(int totalResultsCount)
      this.totalResultsCount = totalResultsCount;


      public List<City> getCities()
      return cities;


      public void setNames(List<City> cities)
      this.cities = cities;





      and



      public class City implements Serializable

      @SerializedName("name")
      @Expose
      private String name;

      public City()


      public City(String name)
      super();
      this.name = name;


      public String getName()
      return name;


      public void setName(String name)
      this.name = name;





      And I complete removed the custom Deserializer.



      It was a combination of my POJO and Wrong choice of RxJava operations which led to my problem. I hope this answer might help someone in the future.



      If anyone have a better solution/way to handle this I would appreciate comments.






      share|improve this answer

























        0












        0








        0







        I manage to solve this.



        I changed my API calls to:



        @GET("searchJSON?")
        Observable<ResponseBody> getPopulation(
        @QueryMap Map<String, String> queries
        );


        And I changed my api call method to:



        public Observable<City> getPopulation(String city) {
        return api
        .getPopulation(city)
        .map(c -> c.getCities().get(0))
        .subscribeOn(Schedulers.io());


        And I changed my Serializeble POJOs to:



        public class ResponseBody implements Serializable


        @SerializedName("totalResultsCount")
        @Expose
        private int totalResultsCount;
        @SerializedName("names")
        @Expose
        private List<City> cities = null;

        public ResponseBody()


        public ResponseBody(int totalResultsCount, List<City> cities)
        super();
        this.totalResultsCount = totalResultsCount;
        this.cities = cities;


        public int getTotalResultsCount()
        return totalResultsCount;


        public void setTotalResultsCount(int totalResultsCount)
        this.totalResultsCount = totalResultsCount;


        public List<City> getCities()
        return cities;


        public void setNames(List<City> cities)
        this.cities = cities;





        and



        public class City implements Serializable

        @SerializedName("name")
        @Expose
        private String name;

        public City()


        public City(String name)
        super();
        this.name = name;


        public String getName()
        return name;


        public void setName(String name)
        this.name = name;





        And I complete removed the custom Deserializer.



        It was a combination of my POJO and Wrong choice of RxJava operations which led to my problem. I hope this answer might help someone in the future.



        If anyone have a better solution/way to handle this I would appreciate comments.






        share|improve this answer













        I manage to solve this.



        I changed my API calls to:



        @GET("searchJSON?")
        Observable<ResponseBody> getPopulation(
        @QueryMap Map<String, String> queries
        );


        And I changed my api call method to:



        public Observable<City> getPopulation(String city) {
        return api
        .getPopulation(city)
        .map(c -> c.getCities().get(0))
        .subscribeOn(Schedulers.io());


        And I changed my Serializeble POJOs to:



        public class ResponseBody implements Serializable


        @SerializedName("totalResultsCount")
        @Expose
        private int totalResultsCount;
        @SerializedName("names")
        @Expose
        private List<City> cities = null;

        public ResponseBody()


        public ResponseBody(int totalResultsCount, List<City> cities)
        super();
        this.totalResultsCount = totalResultsCount;
        this.cities = cities;


        public int getTotalResultsCount()
        return totalResultsCount;


        public void setTotalResultsCount(int totalResultsCount)
        this.totalResultsCount = totalResultsCount;


        public List<City> getCities()
        return cities;


        public void setNames(List<City> cities)
        this.cities = cities;





        and



        public class City implements Serializable

        @SerializedName("name")
        @Expose
        private String name;

        public City()


        public City(String name)
        super();
        this.name = name;


        public String getName()
        return name;


        public void setName(String name)
        this.name = name;





        And I complete removed the custom Deserializer.



        It was a combination of my POJO and Wrong choice of RxJava operations which led to my problem. I hope this answer might help someone in the future.



        If anyone have a better solution/way to handle this I would appreciate comments.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 at 18:57









        CarltonCarlton

        95321638




        95321638



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55054579%2fretrofit-d-response-expected-begin-array-but-was-begin-object-at-line-1-column%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

            List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229