首页 > 编程知识 正文

可序列化,map序列化

时间:2023-05-04 01:51:18 阅读:154378 作者:2422

的集合中具有bigdecimal的处理

定义包含bigdecimal、string的商品信息类

实现可编程

如何重写describeContents和writeToParcel

describeContents方法的默认处理为0。

writeToParcel在序列化过程中将数据写入Parcel对象,并通过Parcel对象处理所有属性,如果是bigdecimal,则写入字符串

3 .实例化静态内部对象CREATOR。 在此,createFromParcel为反序列化处理,对利用writeToParcel方法序列化后的数据进行反序列化。

注意:

在writeToParcel和createFromParcel中调用的protectedgoodinfomodel (parcel in )处理参数的顺序必须相同

以上是序列化的基本流程,当类在Android studio中实现Parcelable后重写方法时,将自动生成上述处理。

以下重点表示了bigdecimal的处理

publicclassgoodinfomodelimplementsparcelable {

私有二进制总;

私有二进制权重;

私有字符串代码否;

私有字符串代码;

私有二进制qty;

protectedgoodinfomodel{

total=new bigdecimal (in.readstring );

weight=new bigdecimal (in.readstring );

goodsno=in.readString (;

barcode=in.readString (;

qty=new bigdecimal (in.readstring ) );

}

publicstaticfinalcreatorcreator=new creator {

@Override

publicgoodinfomodelcreatefromparcel (

returnnewgoodinfomodel(in;

}

@Override

publicgoodinfomodel [ ] new array (intsize ) {

return new GoodInfoModel[size];

}

(;

公共获取工具(

返回总;

}

公共语音集(bigdecimal total ) {

this.total=total;

}

公共二进制获取权重(

返回权重;

}

公共宽度(bigdecimal weight )。

this.weight=weight;

}

公共字符串获取指南no (

return goodsno;

}

publicvoidsetgoodsno (stringgoodsno ) {

this.goodsno=goodsno;

}

公共字符串获取代码

返回条形码;

}

publicvoidsetbarcode (字符串代码) {

this.barcode=barcode;

}

公共二进制获取qty (

返回qty;

}

公共语音集qty (bigdecimal qty ) {

this.qty=qty;

}

@Override

公共说明内容(

返回0;

}

@Override

publicvoidwritetoparcel (parcel dest,int flags ) )。

dst.writestring (getunnullstring (total ','0' ) );

dst.writestring (getunnullstring (weight ','0' ) );

dst.writestring(Goodsno );

dst.writestring(Barcode );

dest.writestring (getunnullstring (qty ','0' ) );

}

//空的判断

privatestringgetunnullstring (strings,String defaultData ) {

return (s==null|| textutils.isempty )|| 'null'.equals(s )? 默认数据

: s;

}

}

订单类别:

publicclassorderinfoimplementsparcelable {

私有列表地理空间;

私有二进制总;

私有计数;

private String flow_no;

publicorderinfo(Parcelin ) {

goodinfomodels=in.createtypedarraylist (goodinfomodel.creator;

total=new bigdecimal (in.readstring );

count=in.readInt (;

flow_no=in.readString (;

}

publicstaticfinalcreatorcreator=new creator {

@Override

publicorderinfocreatefromparcel

returnneworderinfo(in );

}

@Override

publicorderinfo [ ] new array (intsize ) {

return new OrderInfo[size];

}

(;

公共订单信息(

}

//空的判断

privatestringgetunnullstring (strings,String defaultData ) {

return (s==null|| textutils.isempty )|| 'null'.equals(s )? 默认数据

: s;

}

公共列表获取信息模型(

return goodInfoModels;

}

公共视觉识别信息模型(listgoodinfomodels )。

this.goodinfomodels=goodinfomodels;

}

公共获取工具(

返回总;

}

public String getFlow_no

return flow_no;

}

publicvoidsetflow _ no (string flow _ no ) {

this.flow_no=flow_no;

}

公共获取计数

返回计数;

}

publicvoidsetcount(intcount ) {

this.count=count;

}

@Override

公共说明内容(

返回0;

}

@Override

publicvoidwritetoparcel (parcel dest,int flags ) )。

dest.writetypedlist (goodinfomodels;

dest.writestring (getunnullstring (total ',' ) );

dst.writeint(count;

dest.writestring(flow_no );

}

本文地址: https://blog.csdn.net/jiuweitianhu _ 12345/article/details/112240365

如果您有任何问题或要求,请点击回复信息。 成千上万的网友会为你解惑。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。