Shaheen Zahedi
Shaheen Zahedi

Reputation: 1266

Retrieve dynamic JSON using gson and retrofit returns null?

I have a dynamic json with dynamic nested objects, I've created these pojo but the model is always NULL I don't know what've I done wrong.

Here is my JSon

{
    "status": 200,
    "message": "Accepted, Ok",
    "model": {
        "مشخصات کلي": {
            "ابعاد": "125X98X76 ميلي متر",
            "وزن": "480 گرم",
            "ضد آب": false
        },
        "حسگر و تصوير": {
            "محدوده دقت حسگر": "20.0 مگاپيکسل و بيشتر",
            "نوع حسگر": "CMOS",
            "قطع حسگر": "Crop Frame",
            "ابعاد حسگر": "APS-C (23.5 x 15.6 mm)",
            "دقت حسگر": "25 مگاپيکسل",
            "دقت موثر حسگر": "24.2 مگاپيکسل",
            "حداکثر رزولوشن عکس": "6000X4000"
        },
        "لنز": {
            "محدوده زوم": "6 تا 10 برابر بزرگنمايي",
            "فاصله کانوني": "18-140 ميلي متر",
            "محدوده ديافراگم": "F/3.5-5.6",
            "بزرگ نمايي اپتيکال": "7.7 برابر",
            "لرزشگير تصوير": true
        },
        "فيلم": {
            "رزولوشن فيلم": "Full HD",
            "حداکثر سرعت فيلم": "60 فريم بر ثانيه",
            "فيلمبرداري سه بعدي": false
        }
    }
}

and here is the corresponding POJO:

public class ProductTechnicalResponse {
    @SerializedName("status")
    @Expose
    private Integer status;
    @SerializedName("message")
    @Expose
    private String message;
    @SerializedName("model")
    @Expose
    private Model model;
}


class Model {
    Map<String, Map<String,Object>> pairs;
}

Upvotes: 0

Views: 48

Answers (1)

Luk
Luk

Reputation: 2246

Change your POJO to this:

public class ProductTechnicalResponse {
    @SerializedName("status")
    @Expose
    private Integer status;
    @SerializedName("message")
    @Expose
    private String message;
    @SerializedName("model")
    @Expose
    private Map<String, Map<String, Object>> model;
}

model is a map, not a structure with a map.

Upvotes: 1

Related Questions