Gson解析java嵌套类的属性及其属性值,将java类转成java字符串数组,API接口写属性有用

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Gson gson = new GsonBuilder().serializeNulls().enableComplexMapKeySerialization().disableHtmlEscaping().create();
PictrueConditionVo pictrueConditionVo=new PictrueConditionVo();
List pictureTemplates=new ArrayList<>();
pictureTemplates.add(new PictureTemplate());
pictrueConditionVo.setPictureTemplates(pictureTemplates);
Picture label=new Picture();
PictureDivReport pictureDivReport=new PictureDivReport();
pictrueConditionVo.setLabel(label);
/**分析标签层级**/
 List tags = new ArrayList<>();
 tags.add(new PictureDiv());
/**分析标签层级条件与tags数量要一致**/
 List conditions=new ArrayList<>();
conditions.add(new ParentLogicalOperatorConditionPictrueVo());
pictrueConditionVo.setConditions(conditions);
pictrueConditionVo.setPictureDivReport(pictureDivReport);
String json = gson.toJson(pictrueConditionVo);
System.out.println(json);

样列数据

Gson解析java嵌套类的属性及其属性值,将java类转成java字符串数组,API接口写属性有用_第1张图片

{"label":{"createType":null,"pictureName":null,"labelId":null,"modelId":null,"isAuto":null,"sqlinfo":null,"remark":null,"sqlValueName":null,"status":null,"total":null,"pictureDivReport":null,"labelDivList":null,"pictureTemplates":null,"bizType":null,"divName":null,"userName":null,"isMyCreate":0,"isAll":0,"page":null,"rows":null,"id":null,"createUser":null,"createTime":null,"updateUser":null,"updateTime":null,"flag":1,"pageModel":null,"pageMap":null},"tags":null,"conditions":[{"id":0,"logicalOperator":0,"childGroups":null}],"pictureTemplates":[{"name":null,"pictureId":null,"labelId":null,"modelId":null,"templateType":null,"rowName":null,"rowNameCn":null,"columnName":null,"columnNameCn":null,"pictureType":null,"sqlinfo":null,"remark":null,"percentage":null,"pictureDivReportList":null,"id":null,"createUser":null,"createTime":null,"updateUser":null,"updateTime":null,"flag":1,"pageModel":null,"pageMap":null}],"pictureDivReport":{"rowName":null,"columnName":null,"pictureId":null,"templateId":null,"count":null,"total":null,"percentage":null,"sqlinfo":null,"id":null,"createUser":null,"createTime":null,"updateUser":null,"updateTime":null,"flag":1,"pageModel":null,"pageMap":null},"templateIds":null}
{"flag":1,"isMyCreate":0,"isAll":0,"newRecord":true}

你可能感兴趣的:(java技术)