1

i have a problem fetching data using retrofit, i usually using jsonschema2pojo for create object. first i have no problem at all. but after tracing what cause data null is the response.body() not fetching full data, but some of them are called. after searching through the internet, i have answer that the object class is not matching with the response but i dont know what is mean matching at all.

this is my object class

public class KunjunganOutlet {

    @SerializedName("status")
    @Expose
    private Boolean status;
    @SerializedName("message")
    @Expose
    private String message;
    @SerializedName("info")
    @Expose
    private Object info;
    @SerializedName("data")
    @Expose
    private List<Data> data = null;

// and some getter setter

And Data class

public class Data {

        @SerializedName("id")
        @Expose
        private String id;
        @SerializedName("nama")
        @Expose
        private String nama;
        @SerializedName("jenis")
        @Expose
        private String jenis;
        @SerializedName("alamat")
        @Expose
        private String alamat;
        @SerializedName("tlp")
        @Expose
        private String tlp;

// and some getter setter

and here's my data from API

{
    "status": true,
    "message": "Successfully",
    "info": null,
    "data": [
        {
            "id": "47760",
            "nama": "BKKBN Provinsi Aceh",
            "jenis": "KLDI",
            "alamat": "jl.t.nyak arief no 101 banda aceh\r\n",
            "tlp": ""
        },
        {
            "id": "47784",
            "nama": "Dinkes Aceh Selatan",
            "jenis": "Dinas Kesehatan",
            "alamat": "Jl. Teungku Raja Angkasah Tapaktuan Telp. 0656-21829\r\n",
            "tlp": ""
        }
    ]
}

and the result only id that get from data

onResponse: {"data":[{"id":"5287"},{"id":"5185"}],"message":"Successfully","status":true}

UPDATE just wrong call after several attempt

  • 1
    Check what your server is sending you back also you can log the request and response from retrofit that will give you clear idea what response is received at mobile. https://stackoverflow.com/questions/21886313/how-to-log-request-and-response-body-with-retrofit-android – Taranmeet Singh Dec 19 '21 at 12:27
  • `{"status":true,"message":"Successfully","info":null,"data":[{"id":"5287","nama_produk":"ABN ANTISEPTIC"},{"id":"5185","nama_produk":"FRESCO HAND RUB 5000ML"}]}` only that – Fajar Satya Sanjaya Dec 19 '21 at 14:01
  • why does `"alamat","jenis","tlp"` not send?is that anything wrong with my code? – Fajar Satya Sanjaya Dec 19 '21 at 14:05
  • 1
    if the server isn't sending the data you need, then it's a problem on the api, right? not sure how you want to solve this on android, if you're expecting the api to send you the value `Hello world` and it only ever sends `Hello`, then nothing you do from the app will change that. look at the response you get from the server before you parse it. if there are fields missing from the raw json, then this isn't an android problem, either that or the way you're making the request isn't correct, but we have no way of knowing that – a_local_nobody Dec 19 '21 at 14:28
  • Im just so dumb, wrong request.. after rest a bit. I finally get from log okhttp for calling `/product` instead `/outlet` damn took an hour to notice that.. – Fajar Satya Sanjaya Dec 19 '21 at 17:05

1 Answers1

1

Wrong call from the first, after several hours logging, check API and codes. I just realise after checking log from okhttp, request path is /product instead /outlet.