Atitit.atijson 类库的新特性设计与实现 v3 q31
Atitit.atijson 类库的新特性设计与实现 v3 q31
3. V3版本新特性---循环引用解决使用fastjson2
4.2. 多个json类库编译需求jar ,需要同时具备多个json jar类库才可编译成功。。麻烦2
5.1. 自定义json解析库,使用多个复合的json 解析复合的引擎2
5.2. 循环引用暂时使用fastjson解决,最终要限制level解决2
6.2. 没有get set方法的属性自动忽略,而不抛出异常3
6.4. Api使用json lib的,以及gson的也一个3
7. 普通的的json解析器 Jackson类库 Google Gson JSON-lib类库4
8.1. toJson xxx.fromObject(x).toString(2)4
8.2. 字符串转成对象 T fromJson(String str, Class<T> type) fromObject(object)4
1. V1版本---集成了多引擎
2. V2版本新特性 --bsh脚本化
使用了bsh脚本化防止编译错误
3. V3版本新特性---循环引用解决使用fastjson
Fastjson版本放在第一解析器序列
4. prob目前jsonlib库的存在的问题,
4.1. 可能版本冲突,抛出ex
4.2. 多个json类库编译需求jar ,需要同时具备多个json jar类库才可编译成功。。麻烦
4.3. 循环引用的解决
作者:: 绰号:老哇的爪子 ( 全名::Attilax Akbar Al Rapanui 阿提拉克斯 阿克巴 阿尔 拉帕努伊 ) 汉字名:艾龙, EMAIL:1466519819@qq.com
转载请注明来源: http://www.cnblogs.com/attilax/
5. solu解决之道:
5.1. 自定义json解析库,使用多个复合的json 解析复合的引擎
5.2. 循环引用暂时使用fastjson解决,最终要限制level解决
通过反射,变成map,限制层数解决
5.3. 脚本化,防止编译问题的 出现
6. 几个要点
6.1. 复合结构的转换
6.2. 没有get set方法的属性自动忽略,而不抛出异常
6.3. 时间格式的转换
6.4. Api使用json lib的,以及gson的也一个
作者:: 老哇的爪子 Attilax 艾龙, EMAIL:1466519819@qq.com
转载请注明来源: http://www.cnblogs.com/attilax/
6.5. 如果要将泛型转换成json,
1、如,一个Map是这样的,Map<String, Map<String, List<String>>> map,如果这样使用gson.toJson(map)得不到正确的结果的话,那么,我们可能要这样使用,gson.toJson(map,new TypeToken<Map<String, Map<String, List<String>>>>(){}.getType())。
解决方案:
1、如果涉及到关联属性的对象,转换前可以先把它的关联属性转换并放入一个新建的Map或者List,然后按照层次结构重复这样的操作一层一层的往上转,这样,一般可以解决问题,但是,如果关联的层次比较深,做起来就很麻烦了。上面提到的问题3就可以用这种方式解决。
7. 普通的的json解析器 Jackson类库 Google Gson JSON-lib类库
8. Api
8.1. toJson xxx.fromObject(x).toString(2)
8.2. 字符串转成对象 T fromJson(String str, Class<T> type) fromObject(object)
9. Teste code
package com.attilax.json;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.attilax.core;
import com.google.gson.Gson;
public class JSONObject {
public JSONObject(Map m) {
this.obj = m;
}
public static void main(String[] args) {
Map m = new HashMap();
m.put("d", new Date());
// m.put(key, value)
JSONObject.fromObject(m).toString(2);
}
private String toString(int i) {
// if(i==2) //fmt
{
try {
return net.sf.json.JSONObject.fromObject(this.obj).toString(i);
} catch (Exception e) {
try {
// 创建一个gson对象
Gson gson = new Gson();
// 转换成json
String json = gson.toJson(this.obj);
return json;
} catch (Exception e2) {
return JsonUtil4jackjson.buildNormalBinder().toJson(
this.obj);
}
}
}
}
public Object obj;
private static JSONObject fromObject(Map m) {
// TODO Auto-generated method stub
return new JSONObject(m);
}
}
10. 参考
Atitit.序列化循环引用解决方案json
Atitit.atijson 类库的新特性设计与实现 v3 q31的更多相关文章
- Atitit DbServiceV4qb9 数据库查询类库v4 新特性
Atitit DbServiceV4qb9 数据库查询类库v4 新特性 V4新特性 安全特性,屏蔽了executeUpdate,使用v2版 Sql异常转换,特别转换了DuplicateEnt ...
- Atitit mac os 版本 新特性 attilax大总结
Atitit mac os 版本 新特性 attilax大总结 1. Macos概述1 2. 早期2 2.1. Macintosh OS (系统 1.0) 1984年2 2.2. Mac OS 7. ...
- Atitit .c#的未来新特性计划草案
Atitit .c#的未来新特性计划草案 1. C#的未来:追踪空引用1 1.1. 2. 变量命名空间1 1.2. 10. 项目引用Native dll2 1.3. 10. 项目引用Native dl ...
- atitit.ntfs ext 文件系统新特性对比
atitit.ntfs ext 文件系统新特性对比 1. 现代文件系统应该有的特性2 1.1. 恢复Log2 1.2. 压缩2 1.3. Meta ext2 1.4. Fulltextཟsearch ...
- Atitit. Atiposter 发帖机 新特性 poster new feature v7 q39
Atitit. Atiposter 发帖机 新特性 poster new feature v7 q39 V8 重构iocutilV4,use def iocFact...jettyUtil V ...
- Atitit. Atiposter 发帖机 新特性 poster new feature v11 .docx
Atitit. Atiposter 发帖机 新特性 poster new feature v11 .docx 1.1. 版本历史1 2. 1. 未来版本规划2 2.1. V12版本规划2 2.2. ...
- Atitit. Atiposter 发帖机 新特性 poster new feature v7 q39
Atitit. Atiposter 发帖机 新特性 poster new feature v7 q39 V1 初步实现sina csdn cnblogs V2 实现qzone sohu 的发帖 ...
- Atitit hibernate3 hinernate4 hibernate5新特性attilax总结
Atitit hibernate3 hinernate4 hibernate5新特性attilax总结 1.1. Hibernate3的新特性 1 1.2. hibernate4.1版本中的新特性和h ...
- Atitit js es5 es6新特性 attilax总结
Atitit js es5 es6新特性 attilax总结 1.1. JavaScript发展时间轴:1 1.2. 以下是ES6排名前十的最佳特性列表(排名不分先后):1 1.3. Es6 支持情况 ...
随机推荐
- linux历史命令
"忘记历史的Linux用户注定要输入很多信息.” 这也让强有力的历史命令(包括Bash shell的历史变体)不仅在援引之前执行命令而不需重新输入它们时有用,在调用其它很少用到的命令时也有用 ...
- Codechef ForbiddenSum
Mike likes to invent new functions. The latest one he has invented is called ForbiddenSum. Let's con ...
- 【矩阵乘法】bzoj2326 [HNOI2011]数学作业
http://hzwer.com/2831.html #include<cstdio> #include<iostream> #include<vector> us ...
- 将js方法名作为参数传给js方法
1,demo1:参数function无参 <script> function fun1(){ fun3('fun4'); } function fun2(){ fun3('fun5'); ...
- &#x开头的是什么编码?
在 Node 层利用 cheerio 解析网页时,输出的中文内容都是以 &#x 开头的一堆像乱码一样的东西,尝试过各种编码都无效,而且神奇的是,将这一堆“乱码”保存成网页后,通过浏览器打开又可 ...
- Why DNS Based Global Server Load Balancing (GSLB) Doesn’t Work
Why DNS Based Global Server Load Balancing (GSLB) Doesn't Work
- 【js 正则表达式】记录所有在js中使用正则表达式的情况
说实话,对正则表达式有些许的畏惧感,之前的每次只要碰到需要正则表达式去匹配的情况,都会刻意的躲过或者直接从度娘处获取. 此时此刻,感觉到了某一个特定的点去触及她.但笔者对于正则表达式使用上的理解是这样 ...
- 消息队列系列(四):Rabbitmq常用命令行
目录:安装目录下的 ./sbin rabbitmqctl [-n node] [-t timeout] [-q] {command} [command options…] http://www.rab ...
- 采用Apache作为WebLogic Server集群的负载均衡器
强烈建议不要使用WebLogic ClusterServlet作为Proxy进行生产环境的负载均衡, 那个是用来进行集群的功能测试的,Oracle的产品文挡也写得比较清楚. 如果采用软件的负载均衡,可 ...
- ubuntu中apt使用以及centos中yum的使用
centos和ubuntu是两大linux主流阵营 在centos中下载安装软件的方式 rpm rpm命令是RPM软件包的管理工具.rpm原本是Red Hat Linux发行版专门用来管理Linux各 ...