码迷,mamicode.com
首页 > Web开发 > 详细

alibaba fastjson

时间:2017-05-26 10:51:42      阅读:495      评论:0      收藏:0      [点我收藏+]

标签:assign   except   tostring   case   bsp   blog   java   row   wav   

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

 

alibaba fastjson

标签:assign   except   tostring   case   bsp   blog   java   row   wav   

原文地址:http://www.cnblogs.com/tonggc1668/p/6907050.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!