这是课程
class TransactionDetails {
@SerializedName("item")
private String item;
@SerializedName("itemPrice")
private double itemPrice;
@SerializedName("commissions")
private double commissions;
@SerializedName("itemCount")
private double itemCount;
@SerializedName("when")
private long when;
@SerializedName("tax")
private double tax;
TransactionDetails(String item,double itemPrice,double commissions,double itemCount,long when,double tax) {
this.item = item;
this.itemPrice = itemPrice;
this.commissions = commissions;
this.itemCount = itemCount;
this.when = when;
this.tax = tax;
}
String getItem() {
return item;
}
double getItemPrice() {
return itemPrice;
}
double getcommissions() {
return commissions;
}
double getItemCount() {
return itemCount;
}
long getWhen() {
return when;
}
double getTotalPrice() {
return itemCount * itemPrice;
}
String getWhenStr() {
return Utils.getInstance().getDateStr(when);
}
double getTax() {
return tax;
}
}
double getTax()是我在代码中不使用的唯一方法,因为我没有在我的应用程序中使用它,因此我不确定“从未使用过方法getTax()”,尽管我不确定相关
这是实例
ArrayList<TransactionDetails> transactionDetailsFull = new ArrayList<>();
这是失败的代码
new Gson().toJson(Utils.getInstance().transactionDetailsFull);
由于某种原因,以上代码序列化了该类的所有字段(税项除外)。仅在释放模式下会发生这种情况:
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'
在调试模式下,它可以工作。请注意,我做了@SerializedName,所以我不明白我缺少什么以及什么导致仅税项无法序列化。