我使用 GSON 来转换服务器返回的数据类。我像这样定义了数据类......还有一些我不想用 GSON 转换的字段......所以我添加了带有注释的 ExclusionStrategy 。通过测试,发现AnnotationExclusionStrategy运行正常,并跳过不想转换的字段。我添加了带有 uiType 和 testData 等字段的注释,但实际上当我打印对象时。我发现 uiType 和 testData 字段已转换为零和空值..
然后我创建一个新的数据类。uiType 和 testData 没有擦除为零或空值。GSON 转换时会出错吗??
如果有什么办法可以解决这个问题吗?
这是代码。
数据类实体:
data class Product(@SerializedName("num_iid") var productId: Long,
@SerializedName("title") var productName: String,
@SerializedName("item_url") var productUrl: String,
@SerializedName("pict_url") var productPic: String,
@SerializedName("small_images") var productPics: ProductImageList,
@SerializedName("zk_final_price") var productPrice: String,
@SerializedName("reserve_price") var originPrice: String,
@SerializedName("provcity") var place: String,
@SerializedName("volume") var sellCount: String,
@SerializedName("user_type") var sellerType: String,
@SerializedName("nick") var sellerName: String,
@SerializedName("seller_id") var sellerId: Long
) : MultiItemEntity {
@Exclude
@ShoppingCenterConstant.ProductListUiType
var …Run Code Online (Sandbox Code Playgroud)