java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 62 java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 62 json json

java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 62


Actually your were getting error BEGIN_OBJECT but was STRING because gson was expecting object not the string, also it is an object in json, you have wrong mapped your classes in Bean class, and you have not posted the Bean,Simple class glue code here.

You JSON model classes can be mapped as like this

public class ProductInfo {    private boolean success;    private Map<String, String[]> messages;    private SessionData session;    private MetaData metadata;}public class SessionData {    private String id;    private String expire;    private String YII_CSRF_TOKEN;}public class MetaData {    private String product_count;    private String category_ids;    private List<Result> results;}public class Result {    private String id;    private Data data;}public class Data {    private String sku;    private String name;    @SerializedName(value = "new-product")    private String newProduct;    private String url;    Map<String, KeyMap> simples;}public class KeyMap {    private Meta meta;    private Attributes attributes;}public class Meta {    private String sku;;    private String price;    private String caching_hash;    private String shipment_cost_item;    private String shipment_cost_order;    private String tax_percent;    private String quantity;    private String cost;    private String size_brand;    private String size;    private String size_position;    @SerializedName(value = "3hours_shipment_available")    private String hours_shipment_available;    private String estimated_delivery;    private String estimated_delivery_positio;}public class Attributes {    private String sort_order;    private String size;}

Finally de-serialize it

ProductInfo productInfo = gson.fromJson(reader, ProductInfo.class);

Enjoy :)