2013年10月30日星期三

Gson deserialize

When using the google Gson class parses json format string java bean when it came to a question , The JsonDeserializer com.google.gson.DefaultTypeAdapters $ CollectionTypeAdapter @ 1dd21dd2 failed to deserialize json object, given ; the type java.util.List . java bean data format is this : public class Trade {
private String adjustFee;
private Long alipayId;
private List orders;

public List getOrders ()
{
return orders;
}
public void setOrders (List orders)
{
this.orders = orders;
}

public String getAdjustFee ()
{
return adjustFee;
}
public void setAdjustFee (String adjustFee)
{
this.adjustFee = adjustFee;
}
public Long getAlipayId ()
{
return alipayId;
}
public void setAlipayId (Long alipayId)
{
this.alipayId = alipayId;
}
}
public class Order {
private String adjustFee;
private String buyerNick;
public String getAdjustFee ()
{
return adjustFee;
}
public void setAdjustFee (String adjustFee)
{
this.adjustFee = adjustFee;
}
public String getBuyerNick ()
{
return buyerNick;
}
public void setBuyerNick (String buyerNick)
{
this.buyerNick = buyerNick;
}
}
Trade category in which there is a List, which is stored Order, just do not use generics , java bean not all the properties are given only the attributes associated with abnormal (Order), and then call the method Gson go to json string into an object Trade , Trade trade = gson.fromJson (json, Trade.class); then throw the exception mentioned above . It is this question , there is a java bean property of type Collection , how to achieve the use Gson deserialize ? Find great God guide !
------ Solution ---------------------------------------- ----
encountered the same problem , the landlord has to solve it ?
------ Solution ---------------------------------------- ----

- ----- For reference only ---------------------------------------
resolved, the project serialization is used when processing json taobao the jar, and then I had to use when deserializing the google 's Gson tools , hence the above problems , the specific reasons did not go to see , look after to the project json serialization is used when operating the json package taobao tools, tools taobao json went to see the source code , and then use the tools in taobao json jar class deserialized .

没有评论:

发表评论