How to ignore some variables in models using for retrofit

You can use transient keyword to ignore fields when requesting api calls

JAVA:

transient String name;

KOTLIN:

@Transient
var name: String

Use transient keywork for that

public class SelectedListModel implements Serializable {

  @SerializedName("p_id")
  @Expose
  private Long pId;

  @SerializedName("p_qty")
  @Expose
  private Double pQty;

  //@Expose(serialize = false , deserialize = false)
  private transient String pName; //Have not to send to server

  //@Expose(serialize = false , deserialize = false)
  private transient String pPrice; //Have not to send to server

  //@Expose(serialize = false , deserialize = false)
  private transient String pImageUrl; //Have not to send to server
}

and no need to use @Expose(serialize = false , deserialize = false), into those fields which needed to be excluded.


Read Why does Java have transient fields? and Why use the `transient` keyword in java? for more details.