1.java代码
为了解决Map不支持序列化的问题,
特意定义了一个数组(里面用到了List来做转换)
迎合序列化的需要
@Expose
@XStreamAlias("TheFroms")
@SerializedName("TheFroms")
public OrderFromInfo[] theFroms;
@Expose
@XStreamAlias("Froms")
@SerializedName("Froms")
public Map Froms;
private Map froms = new HashMap();
/**
* new一个List来做Map数组的转换
*Author:shaorongfei
* @return new
*/
public OrderFromInfo[] getTheFroms() {
List theItems = new ArrayList();
if (froms != null) {
for (OrderFromInfo orderFromInfo : froms.values()) {
theItems.add(orderFromInfo);
}
}
final int size = theItems.size();
theFroms = (OrderFromInfo[]) theItems.toArray(new OrderFromInfo[size]);
return theFroms;
}
/**
* 迎合序列化需要,数组等同Froms属性。
* Author:shaorongfei
* @param theFroms 传入的OrderFromInfo[]数组
*/
public void setTheFroms(OrderFromInfo[] theFroms) {
froms = new HashMap();
for (OrderFromInfo item : theFroms) {
froms.put(item.getRftype(), item);
}
}
public Map getFroms() {
return froms;
}
public void setFroms(Map froms) {
this.froms = froms;
}
2.C#代码
以上需要的朋友可以借此来试一试,在做Xml序列化时项目里经常会用到。
网站标题:.net和java中不支持字典的序列化的变通方法
网站URL:
http://cdxtjz.cn/article/poccph.html