zoukankan      html  css  js  c++  java
  • alibaba fastjson

    public static void main(String[] args) {
        WaveSearchOutBoundNoticeDTO vo = new WaveSearchOutBoundNoticeDTO();
        List<OutboundNoticeGroupSortDTO> groupSorts= new ArrayList<OutboundNoticeGroupSortDTO>();
        vo.setOnhStartItemsCount(1);
        vo.setGroupSorts(groupSorts);
        OutboundNoticeGroupSortDTO dto = new OutboundNoticeGroupSortDTO();
        dto.setColumn("column");
        dto.setSort("sort");
        dto.setOrder(1);
        groupSorts.add(dto);
        OutboundNoticeHVO criteriaHead = new OutboundNoticeHVO();
        vo.setCriteriaHead(criteriaHead);
        criteriaHead.setOnhOrderPriority(1);
        String jsonStr = JSON.toJSONString(vo);
        System.out.println(jsonStr);
        WaveSearchOutBoundNoticeDTO result= JSON.parseObject(jsonStr, WaveSearchOutBoundNoticeDTO.class);
        jsonStr = JSON.toJSONString(result);
        System.out.println(jsonStr);
    
    }
    if (format.equalsIgnoreCase("json") {
                try {
                    // alibaba fastjson 
                    if(Collection.class.isAssignableFrom(clazz)) {
                        JSONArray data = (JSONArray) request.getData();
                        result = JSON.parseArray(data.toJSONString(), genricClazz);
                        //JSON.toJavaObject(data, genricClazz);
                    } else {
                        if(JSONObject.class.isAssignableFrom(request.getData().getClass())) {
                            JSONObject data = (JSONObject) request.getData();
                            result = JSON.toJavaObject(data, clazz); 
                        } else {
                            if(String.class.isAssignableFrom(clazz)) {
                                result = request.getData();
                            } else {
                                result= JSON.parseObject(request.getData().toString(), clazz);
                            }
                        }
                    }
                } catch (Exception e) {
                    logger.error(e.getMessage());
                    throw new PayloadConvertException(e);
                }
            }

     string转list

    import com.alibaba.fastjson.JSONArray;

    String jsonStr = JSON.toJSONString(data);
    List<RivWaveRoundPickL> waveRoundPickList = JSONArray.parseArray(jsonStr, RivWaveRoundPickL.class);

     
  • 相关阅读:
    python3.5以上版本,typing模块提高代码健壮性
    psutil模块使用
    不懂前后端分离?这篇就够了
    k8s krew 插件管理工具
    metrics-server 安装问题解决
    k8s dashboard 解决secret自建证书导致浏览器访问限制
    创建私有 Gems 源
    windows10 使用WSL(ubuntu系统,xshell连接)
    将 Oracle VirtualBox 中运行的虚拟机导入 VMware Fusion、Workstation 或 Player
    conflunce安装配置
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/6907050.html
Copyright © 2011-2022 走看看