如何忽略用于改造的模型中的某些变量 [英] How to ignore some variables in models using for retrofit

查看:84
本文介绍了如何忽略用于改造的模型中的某些变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Retrofit 向我的服务器发送和接收请求.

I am using Retrofit to send and receive requests to my server.

我有一个如下所示的模型,我必须将其发送到服务器,但是此模型中的某些变量没有发送到服务器.

I Have a model like below and I have to send it to my server but some variables in this model have not to send to the server.

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 String pName; //Have not to send to server

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

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

,因此,我从服务器得到的响应为400. 我使用@Expose(serialize = false, deserialize = false)来忽略不必发送到服务器的变量. 但这是行不通的. 有什么方法可以做,还是我必须为我的服务器创建另一个模型?

and because of that, I am getting 400 in my responses from the server. I used of @Expose(serialize = false, deserialize = false) in order to Ignore variables that have not to send to the server. But it doesn't work. Is there any way to do this or I have to create another model just for my server?

推荐答案

使用

,并且无需使用@Expose(serialize = false , deserialize = false)进入需要排除的字段.

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

阅读为什么Java有过渡字段?以获取更多详细信息.

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

这篇关于如何忽略用于改造的模型中的某些变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆