• 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);

     
  • 相关阅读:
    一步步构建大型网站架构
    IIS访问设置
    如何删除windows中的服务
    IIS下对WebConfig加密后无法访问网站
    ConfigurationManager不认的问题
    ORA12514: TNS: 监听程序当前无法识别连接描述符中请求的服务
    PostgreSQL中表和字符串大写的问题
    ASP.NET中注册客户端脚本的三种方式
    装箱(boxing)和拆箱(unboxing)
    windows开启防火墙后IIS下的网站外网无法访问
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/6907050.html
Copyright © 2020-2023  润新知