Creating a simple Java Response Class from a Json Response

  android, java, json, postman

I want to build a simple Response class for my nestetd and dynamic Json Response. I recently build my Response class with boolean error, String message and a List<User> user, but if i try to work with the List (for example i want to put out the size of the list or get a user from the list, the applikation returns an error)

Every time i try to get the response message with standardResponse.getMessage() it works, but when i try to open a user from the List, the applikation returns an error?

My dynamic json response:

    "error": false,
    "message": "API-Request successful",
    "user": {
        "0": {
            "userID": 11,
            "firstName": "David",
            "userName": "david",
            "birthDate": "2020-10-19",
            "gender": 1,
            "country": "Linz",
            "aboutmeText": "Testeintrag 3",
            "status": "I like Lookly."
        "1": {
            "userID": 43,
            "firstName": "Sarah",
            "userName": "sarahh",
            "birthDate": "2001-12-14",
            "gender": 0,
            "country": "Austria",
            "aboutmeText": "Lookly ist eine hervorragende App!",
            "status": "Hey there! I am using Lookly."

My Java Response class:

public class StandardResponse {
    boolean error;
    String message;
    List<User> users;

    public boolean isError() {
        return error;

    public String getMessage() {
        return message;

    public List<User> getUsers() {
        return users;
    public class User{
        private int userID;
        private String firstName;
        private String userName;
        private String birthDate;
        private String gender;
        private String country;
        private String aboutmeText;
        private String status;

My Test Request Class in which i try to get back the size of the List<User>

public void updateListView(String latitude, String longitude) {
        Call<StandardResponse> call = RetrofitClient

        call.enqueue(new Callback<StandardResponse>() {
            public void onResponse(Call<StandardResponse> call, Response<StandardResponse> response) {
                StandardResponse standardResponse =  response.body();
                if(response.isSuccessful()) {
                    int size = standardResponse.getUsers().size();
                    Log.d("Response message", standardResponse.getMessage());
                    Log.d("Size ", "" + size);
                else  {
                    Log.d("Response errorBody", String.valueOf(response.errorBody()));

            public void onFailure(Call<StandardResponse> call, Throwable t) {
                String message = t.getMessage();
                Log.e("onFailure", message);


E/AndroidRuntime: FATAL EXCEPTION: main
    Process: at.lookly.apitestapplikation, PID: 1056
    java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.indexOf(java.lang.Object)' on a null object reference
        at at.lookly.apitestapplikation.activities.TestRequest$2.onResponse(
        at retrofit2.DefaultCallAdapterFactory$ExecutorCallbackCall$1.lambda$onResponse$0$DefaultCallAdapterFactory$ExecutorCallbackCall$1(
        at retrofit2.-$$Lambda$DefaultCallAdapterFactory$ExecutorCallbackCall$1$ Source:6)
        at android.os.Handler.handleCallback(
        at android.os.Handler.dispatchMessage(
        at android.os.Looper.loop(
        at java.lang.reflect.Method.invoke(Native Method)

Source: Android Questions