Gson: How do I parse polymorphic values that can be either lists or strings?
问题 I need to parse a JSON file that contains long list of customers. In the JSON file each customer may have one id as a string: { "cust_id": "87655", ... }, or a few ids as an array: { "cust_id": [ "12345", "45678" ], ... }, The Customer class is as below: public class Customer { @SerializedName("cust_id") @Expose private String custId; public String getCustId() { return custId; } public void setCustId(String custId) { this.custId = custId; } } I parse the JSON using Gson: Gson gson = new Gson(