欢迎光临
感受代码之美

使用fastjson实现Map和Java Bean互转

MapJava Bean

public ResponseResult addDataTable(Map<String, Object> params) {
        String jsonString = JSON.toJSONString(params);
        DmDataTable dataTable = JSON.parseObject(jsonString, DmDataTable.class);
        DmApprovalInfo approvalInfo = JSON.parseObject(jsonString, DmApprovalInfo.class);
        return new ResponseResult(insertSelective(dataTable.setTableId(UUIDUtil.uuid())));
    }

Java BeanMap

OrganStaffDto staffDto = queryStaffDtoByOrganId(user2.get("organId"));
String jsonStr = JSON.toJSONString(staffDto);
Map<String,String> staffMap = (Map)JSON.parseObject(jsonStr);

References

  1. fastjson:javabean按字段(field)序列化存储为Map并反序列化
未经允许禁止转载:四个空格 » 使用fastjson实现Map和Java Bean互转

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址