1

How to mention "Required" and "Optional" fields in the Response class of Retrofit2. In my case this is the response of API call

Json Class:

{
"id":"133544", //Required
"name":"abcd" //Optional

}

ModelClass :

public class User {


    @SerializedName("id")
    private String id;

    @SerializedName("name")
    private String name;

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }


    }

How to differentiate the required and optional fields here?

coroutineDispatcher
  • 6,476
  • 5
  • 27
  • 54

1 Answers1

0

Gson will set your serialized fields value to null. In your example if the JSON response you are getting does not include a field name, the resulting POJO will have null for the name.

Rene Ferrari
  • 3,826
  • 3
  • 23
  • 26