GreedDao创建的实体与Json字符串之间的转化

1.GreenDao创建的额Entity转化为Json字符串:
某个Entity -> EcmsSalTemp具有的属性

    @Id
    @Property(nameInDb = "SALTEMPLOCALID")
    @NotNull
    private String salTempLocalId;

    @Property(nameInDb = "SAL_TEMP_LOCAL_NO")
    private String salTempLocalNo;

    @Property(nameInDb = "SALTEMPID")
    private String salTempId;

    @Property(nameInDb = "STOREID")
    private String storeId;

    @Property(nameInDb = "MEMBERID")
    private String memberId;

    @Property(nameInDb = "DTLLINES")
    private String dtlLines;

    @Property(nameInDb = "INPUTMANID")
    private String inputManId;

    @Property(nameInDb = "INPUTMANNAME")
    private String inputManName;

    @Property(nameInDb = "INPUTDATE")
    private java.util.Date inputDate;

    @Property(nameInDb = "RECIPEID")
    private String recipeId;

    @Property(nameInDb = "RECIPENO")
    private String recipeNo;

    @Property(nameInDb = "MEMBERNO")
    private String memberNo;

    @Property(nameInDb = "MEMBERNAME")
    private String memberName;

    @Property(nameInDb = "MEMBERINFO")
    private String memberInfo;

    @Property(nameInDb = "MEDICNAME")
    private String medicName;

    @Property(nameInDb = "CARDNO")
    private String cardNo;

    @Property(nameInDb = "TOTALMONEY")
    private String totalMoney;

    @Property(nameInDb = "DRUGCOUNT")
    private String drugCount;

    @Property(nameInDb = "CARDTYPE")
    private String cardType;

    @Property(nameInDb = "MEMBERDISCOUNT")
    private String memberDiscount;

    @Property(nameInDb = "MEDIMAN")
    private String mediMan;

    @Property(nameInDb = "PARTNERID")
    private String partnerId;

    @Property(nameInDb = "TEL")
    private String tel;

    @Property(nameInDb = "NAME")
    private String name;

    @Property(nameInDb = "IDCARDNO")
    private String idCardNo;

    @Property(nameInDb = "DISCOUNT")
    private String discount;

    @Property(nameInDb = "ORDERNO")
    private String orderNo;

    @Property(nameInDb = "ORDERDATE")
    private String orderDate;

    @Property(nameInDb = "ADDRESS")
    private String address;

    @Property(nameInDb = "LINKNAME")
    private String linkName;

    @Property(nameInDb = "LINKPHONE")
    private String linkPhone;

    @Property(nameInDb = "DELIVERYTYPE")
    private String deliveryType;

    @Property(nameInDb = "PAYTYPE")
    private String payType;

    @Property(nameInDb = "PAYSTATUS")
    private String payStatus;

    @Property(nameInDb = "SALTEMPTYPE")
    private String salTempType;

    @Property(nameInDb = "PICKMAN")
    private String pickMan;

    @Property(nameInDb = "PICKTIME")
    private String pickTime;

    @Property(nameInDb = "MANID")
    private String manId;

    @Property(nameInDb = "DEALSTATUS")
    private String dealStatus;

里面具有很多的属性,接下来我们创建这个实体的对象并设置值:

 EcmsSalTemp ecmsSalTemp = new EcmsSalTemp();
 ecmsSalTemp.setPickMan("xiaoma");
 ecmsSalTemp.setManId("27458");
 ecmsSalTemp.setStoreId("87452");

可以看出我只是设置了三个值,而我的EcmsSalTemp实体却有好多的属性,接下来我们将这个对象转化成json字符串:

 String s = JSON.toJSONString(ecmsSalTemp);//使用fastJson
 Log.v("xiaoma", "EcmsSalTemp的json是: " + s);

输出结果为:

 V/xiaoma: EcmsSalTemp的json是: {"manId":"27458","pickMan":"xiaoma","storeId":"87452"}

里面只有三个字段的json字符串,就是说没有设置的属性是不会被转化成json字符串的字段的

2.将上面的json字符串转为EcmsPalTemp实例:

 EcmsSalTemp ecmsSalTemp1 = JSON.parseObject(s, EcmsSalTemp.class);//使用fastJson

经过Debug可看出得到的ecmsSalTemp1对象结构如下:


GreedDao创建的实体与Json字符串之间的转化_第1张图片
EcmsSalTemp.PNG

就结果可知,只有设置了值的才会存到实例中,没有的置为null

你可能感兴趣的:(GreedDao创建的实体与Json字符串之间的转化)