How to retrieve a value from list in retrofit

here my module

public class SPSOnHand { 
    @SerializedName("ITEM_CODE")
    @Expose
    private String ITEM_CODE;
    @SerializedName("ITEM_DESCRIPTION")
    @Expose
    private String ITEM_DESCRIPTION;

    public String getITEM_CODE() {
        return ITEM_CODE;
    }

    public void setITEM_CODE(String item_code) {
        ITEM_CODE = item_code;
    }

    public String getITEM_DESCRIPTION() {
        return ITEM_DESCRIPTION;
    }

    public void setITEM_DESCRIPTION(String item_description) {
        ITEM_DESCRIPTION = item_description;
    }

here my rest service class

public class RestService {

    private static final String URL = "http://localhost:58364/";
    private retrofit.RestAdapter restAdapter;
    //private InstituteService apiService;
    private SPInventoryService apiService;

    public RestService()
    {
        restAdapter = new retrofit.RestAdapter.Builder()
                .setEndpoint(URL)
                .setLogLevel(retrofit.RestAdapter.LogLevel.FULL)
                .build();

        apiService = restAdapter.create(SPInventoryService.class);
    }

    public SPInventoryService getService()
    {
        return apiService;
    }

here my service

@GET("/api/SPSOnHand/itemcode/{item_code}")
public void getItemCode(@Path("item_code") String itemcode, 
Callback<ArrayList<SPSOnHand>>callback);

here my main activity class

        String itemcode;
        Intent intent = getIntent();
        itemcode =intent.getStringExtra("itemcode");

            restService.getService().getItemCode(itemcode, new Callback<ArrayList<SPSOnHand>>() {

                @Override
                public void success(ArrayList<SPSOnHand> spsOnHands, Response response) {
                    item_description.setText(String.valueOf(spsOnHands.get(0)));

                }

                @Override
                public void failure(RetrofitError error) {
                    Toast.makeText(AirJet.this, error.getMessage().toString(), 
                Toast.LENGTH_LONG).show();

                }
            });

enter image description here

I want that item_description to contain a word like this

"ID": 167,
"ITEM_CODE": "3020240002",
"ITEM_DESCRIPTION": "CONTROLLER LME22.331c2 (CONTROL BOX)"

thanks in advance, I’m still a newbie in retrofit

Answer

In your case, you receive ArrayList. And if you want to get the item from List then you have to pass index and get value List, like below. It will give you ITEM_DESCRIPTION for the 0th index of your List.

restService.getService().getItemCode(itemcode, new Callback<ArrayList<SPSOnHand>>() {

                @Override
                public void success(ArrayList<SPSOnHand> spsOnHands, Response response) {
                    item_description.setText(String.valueOf(spsOnHands.get(0).ITEM_DESCRIPTION));

                }

                @Override
                public void failure(RetrofitError error) {
                    Toast.makeText(AirJet.this, error.getMessage().toString(), 
                Toast.LENGTH_LONG).show();

                }
            });