Retrofit2: expected BEGIN_ARRAY, but there was STRING in row 1 of column 268 path $ [0] .images

I know this is not the first time someone asks about this problem, but with Retrofit2. I can not find the right solution to my problem.

I have an object containing a String list. when I want to convert the JSON response to my object, all other fields are fine, but I got this error to convert a list of strings to my list:

Retrofit2: Expected BEGIN_ARRAY but was STRING at line 1 column 268 path $[0].images

This is my API:

@POST("/cp/api/")// get list of products
    Call<List<Product>> Get_Special_Products(@Body Object request);

My setup:

public Retrofit Store_retrofit(OkHttpClient client) {
        return new Retrofit.Builder()
                .baseUrl(Urls.Sotre_Base_Url)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

My object:

public class Product implements Serializable {
    @SerializedName("id")
    private int id;
    @SerializedName("user_id")
    private int user_id;
    @SerializedName("cat_id")
    private int cat_id;
    @SerializedName("title")
    private String title;
    @SerializedName("description")
    private String description;
    @SerializedName("image")
    private String image;
    @SerializedName("images")
    private List<String> images;
public int getUser_id() {
        return user_id;
    }

    public int getCat_id() {
        return cat_id;
    }

    public String getTitle() {
        return title;
    }

    public String getDescription() {
        return description;
    }

    public String getImage() {
        return image;
    }
public List<String> getImages() {
        return images;
    }
}

and this is the part of JSON that causes the error for the image:

images:[
    "1487801544.jpg","1487801544.jpg","1487801544.jpg"
]
+4
source share
1 answer

, API json, retrofit String. API, json:)

"images": "[\"1487801544.jpg\",\"1487801544.jpg\",\"148801544.jpg\"]"

:

"images": [
      "1487801544.jpg",
      "1487801544.jpg",
      "1487801544.jpg"
    ]
+3

Source: https://habr.com/ru/post/1678065/


All Articles