- 浏览: 202489 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (196)
- Git (16)
- maven (8)
- Python (20)
- linux (14)
- java (30)
- spring (5)
- javascript (4)
- oracle (15)
- jquery (4)
- jbpm4.4 (4)
- ibatis (1)
- svn (1)
- sql server (1)
- sqoop (1)
- photoshop (2)
- 日常记录 (5)
- scala (1)
- IntelliJ IDEA (7)
- mysql (2)
- Hive (1)
- visual studio code (3)
- angularjs (5)
- nodejs (4)
- gradle (1)
- springboot (4)
- jakson (1)
- hibernate (2)
- 面试 (5)
- React (2)
- Kotlin (1)
- Netty (0)
- webstorm (2)
- spring cloud (4)
- redis (1)
- PowerDesigner (1)
- Vue (4)
- easyui (1)
- activiti (2)
- httpClient4.5 (2)
- logback (3)
- ngrinder (1)
- 分库分表 (1)
最新评论
-
严东军:
学习了,谢谢
摘录--DBMS_SCHEDULER -
zwllxs:
你知道你调的是谁的代码不?
jbpm4.4+ssh2 完整请假流程
package jms.test;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import jms.model.Dept;
import jms.model.Employee;
import jms.model.Student;
import org.junit.Test;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
public class TestFastjson {
//fastjson序列化单个对象 与反序列化
@Test
public void test1() {
Employee e = new Employee("001", "张三", 23, new Date());
//序列化
String jsonStr = JSON.toJSONString(e);
System.out.println(jsonStr);
//反序列化
Employee emp = JSON.parseObject(jsonStr, Employee.class);
System.out.println(emp.getName());
}
//fastjson序列化list集合 与反序列化
@Test
public void test2() {
Employee e = new Employee("001", "张三", 23, new Date());
Employee e2 = new Employee("002", "李四", 29, new Date());
List<Employee> emps = new ArrayList<Employee>();
emps.add(e);
emps.add(e2);
//fastjson序列化list, 返回来的是一个json数组,由[]包含两个json
String jsonArryStr = JSON.toJSONString(emps);
System.out.println(jsonArryStr);
// //反序列化
//法一
// List<Employee> empList = JSON.parseObject(jsonArryStr, new TypeReference<List<Employee>>(){} );
//法二
List<Employee> empList = JSON.parseArray(jsonArryStr,Employee.class);
for (Employee employee : empList) {
System.out.println(employee.getName());
System.out.println(employee.getBirthDay());
}
}
//fastjson序列化复杂对象 与反序列化
@Test
public void test3() {
Employee e = new Employee("001", "张三", 23, new Date());
Employee e2 = new Employee("002", "李四", 29, new Date());
List<Employee> emps = new ArrayList<Employee>();
emps.add(e);
emps.add(e2);
Dept dept = new Dept("d001", "研发部", emps);
//序列化
String jsonStr = JSON.toJSONString(dept);
System.out.println(jsonStr);
//反序列化
Dept d = JSON.parseObject(jsonStr, Dept.class);
System.out.println(d.getName());
//json转map
//法一
Map<String, Object> map1 = JSON.parseObject(jsonStr);//返回JSONObject,JSONObject实现Map<String, Object>接口
//法二
// Map<String, Object> map1 = (Map<String, Object>)JSON.parse(jsonStr);
for (String key : map1.keySet()) {
System.out.println(key + ":" + map1.get(key));
}
}
//fastjson 的 JSONObject的使用
@Test
public void test4() {
Employee e = new Employee("001", "张三", 23, new Date());
//序列化
String jsonStr = JSON.toJSONString(e);
System.out.println(jsonStr);
//反序列化 (可以和test1比较)
JSONObject emp = JSON.parseObject(jsonStr, JSONObject.class);
System.out.println(emp);
System.out.println(emp.getString("name"));
//再放一个Employee不存在的字段
emp.put("salary", "8000");
System.out.println(emp.toJSONString());
System.out.println(emp.get("salary"));
}
//fastjson序列化字符串
@Test
public void test5(){
List<String> strs = new ArrayList<String>();
strs.add("hello");
strs.add("world");
strs.add("banana");
//序列化
String jsonStr = JSON.toJSONString(strs);
System.out.println(jsonStr);
//反序列化
List<String> strList = JSON.parseObject(jsonStr, new TypeReference<List<String>>(){} );
// List<String> strList = JSON.parseArray(jsonStr, String.class);//等同于上一句
for (String str : strList) {
System.out.println(str);
}
}
//fastjson过滤字段
@Test
public void test6() {
Employee e = new Employee("001", "张三", 23, new Date());
Employee e2 = new Employee("002", "李四", 29, new Date());
List<Employee> emps = new ArrayList<Employee>();
emps.add(e);
emps.add(e2);
//构造过滤器
SimplePropertyPreFilter filter = new SimplePropertyPreFilter(Employee.class, "id", "age");
String jsonStr =JSON.toJSONString(emps, filter);
System.out.println(jsonStr);
}
//fastjson 日期处理
@Test
public void test7(){
Date date = new Date();
String dateStr = JSON.toJSONString(date);
System.out.println(dateStr);
String dateStr2 = JSON.toJSONStringWithDateFormat(date, "yyyy-MM-dd HH:mm:ss");
System.out.println(dateStr2);
//序列化实体
Employee emp = new Employee("001", "张三", 23, new Date());
//法一
String empStr = JSON.toJSONStringWithDateFormat(emp, "yyyy-MM-dd HH:mm:ss");
System.out.println(empStr);
//法二
String empStr2 = JSON.toJSONString(emp, SerializerFeature.WriteDateUseDateFormat);
System.out.println(empStr2);
//法三
SerializeConfig config = new SerializeConfig();
config.put(Date.class, new SimpleDateFormatSerializer("yyyy年MM月dd日 HH时mm分ss秒"));
String empStr3 = JSON.toJSONString(emp, config);
System.out.println(empStr3);
}
//fastjson 去掉值的双引号 实现JSONAware接口
@Test
public void test8(){
//见同级目录的Function.java
}
//fastjson 注解形式 (别名命名, 过滤字段, 日期格式)
@Test
public void test9(){
Student stu = new Student("001", "张三", 23, new Date());
String jsonStr = JSON.toJSONString(stu);
System.out.println(jsonStr);
}
}
转载:http://changxianbest.iteye.com/blog/2181891
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import jms.model.Dept;
import jms.model.Employee;
import jms.model.Student;
import org.junit.Test;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
import com.alibaba.fastjson.serializer.SimplePropertyPreFilter;
public class TestFastjson {
//fastjson序列化单个对象 与反序列化
@Test
public void test1() {
Employee e = new Employee("001", "张三", 23, new Date());
//序列化
String jsonStr = JSON.toJSONString(e);
System.out.println(jsonStr);
//反序列化
Employee emp = JSON.parseObject(jsonStr, Employee.class);
System.out.println(emp.getName());
}
//fastjson序列化list集合 与反序列化
@Test
public void test2() {
Employee e = new Employee("001", "张三", 23, new Date());
Employee e2 = new Employee("002", "李四", 29, new Date());
List<Employee> emps = new ArrayList<Employee>();
emps.add(e);
emps.add(e2);
//fastjson序列化list, 返回来的是一个json数组,由[]包含两个json
String jsonArryStr = JSON.toJSONString(emps);
System.out.println(jsonArryStr);
// //反序列化
//法一
// List<Employee> empList = JSON.parseObject(jsonArryStr, new TypeReference<List<Employee>>(){} );
//法二
List<Employee> empList = JSON.parseArray(jsonArryStr,Employee.class);
for (Employee employee : empList) {
System.out.println(employee.getName());
System.out.println(employee.getBirthDay());
}
}
//fastjson序列化复杂对象 与反序列化
@Test
public void test3() {
Employee e = new Employee("001", "张三", 23, new Date());
Employee e2 = new Employee("002", "李四", 29, new Date());
List<Employee> emps = new ArrayList<Employee>();
emps.add(e);
emps.add(e2);
Dept dept = new Dept("d001", "研发部", emps);
//序列化
String jsonStr = JSON.toJSONString(dept);
System.out.println(jsonStr);
//反序列化
Dept d = JSON.parseObject(jsonStr, Dept.class);
System.out.println(d.getName());
//json转map
//法一
Map<String, Object> map1 = JSON.parseObject(jsonStr);//返回JSONObject,JSONObject实现Map<String, Object>接口
//法二
// Map<String, Object> map1 = (Map<String, Object>)JSON.parse(jsonStr);
for (String key : map1.keySet()) {
System.out.println(key + ":" + map1.get(key));
}
}
//fastjson 的 JSONObject的使用
@Test
public void test4() {
Employee e = new Employee("001", "张三", 23, new Date());
//序列化
String jsonStr = JSON.toJSONString(e);
System.out.println(jsonStr);
//反序列化 (可以和test1比较)
JSONObject emp = JSON.parseObject(jsonStr, JSONObject.class);
System.out.println(emp);
System.out.println(emp.getString("name"));
//再放一个Employee不存在的字段
emp.put("salary", "8000");
System.out.println(emp.toJSONString());
System.out.println(emp.get("salary"));
}
//fastjson序列化字符串
@Test
public void test5(){
List<String> strs = new ArrayList<String>();
strs.add("hello");
strs.add("world");
strs.add("banana");
//序列化
String jsonStr = JSON.toJSONString(strs);
System.out.println(jsonStr);
//反序列化
List<String> strList = JSON.parseObject(jsonStr, new TypeReference<List<String>>(){} );
// List<String> strList = JSON.parseArray(jsonStr, String.class);//等同于上一句
for (String str : strList) {
System.out.println(str);
}
}
//fastjson过滤字段
@Test
public void test6() {
Employee e = new Employee("001", "张三", 23, new Date());
Employee e2 = new Employee("002", "李四", 29, new Date());
List<Employee> emps = new ArrayList<Employee>();
emps.add(e);
emps.add(e2);
//构造过滤器
SimplePropertyPreFilter filter = new SimplePropertyPreFilter(Employee.class, "id", "age");
String jsonStr =JSON.toJSONString(emps, filter);
System.out.println(jsonStr);
}
//fastjson 日期处理
@Test
public void test7(){
Date date = new Date();
String dateStr = JSON.toJSONString(date);
System.out.println(dateStr);
String dateStr2 = JSON.toJSONStringWithDateFormat(date, "yyyy-MM-dd HH:mm:ss");
System.out.println(dateStr2);
//序列化实体
Employee emp = new Employee("001", "张三", 23, new Date());
//法一
String empStr = JSON.toJSONStringWithDateFormat(emp, "yyyy-MM-dd HH:mm:ss");
System.out.println(empStr);
//法二
String empStr2 = JSON.toJSONString(emp, SerializerFeature.WriteDateUseDateFormat);
System.out.println(empStr2);
//法三
SerializeConfig config = new SerializeConfig();
config.put(Date.class, new SimpleDateFormatSerializer("yyyy年MM月dd日 HH时mm分ss秒"));
String empStr3 = JSON.toJSONString(emp, config);
System.out.println(empStr3);
}
//fastjson 去掉值的双引号 实现JSONAware接口
@Test
public void test8(){
//见同级目录的Function.java
}
//fastjson 注解形式 (别名命名, 过滤字段, 日期格式)
@Test
public void test9(){
Student stu = new Student("001", "张三", 23, new Date());
String jsonStr = JSON.toJSONString(stu);
System.out.println(jsonStr);
}
}
转载:http://changxianbest.iteye.com/blog/2181891
发表评论
-
开源的 API 网关项目
2018-01-30 15:35 924微服务中的 API 网关(API Gateway) [url] ... -
生成文字图片
2018-01-20 11:05 514import javax.imageio.ImageI ... -
httpClient 上传附件
2018-01-16 10:48 1047import org.apache.http.Http ... -
使用jacob调用office组件将word转换为pdf
2018-01-10 10:02 312使用jacob调用office组件将word转换为pdf 只 ... -
JVM性能调优监控工具jps、jstack、jmap、jhat、jstat、hprof使用详解
2017-04-08 10:20 397JVM性能调优监控工具jps、jstack、jmap、jhat ... -
Failed to read schema document dubbo.xsd
2017-03-27 17:11 372http://blog.csdn.net/wxydaisy/a ... -
java优秀博文
2016-08-08 15:06 415java优秀博文: http://www.holl ... -
fastjson中遇到的坑
2016-06-12 16:35 929public static void main(String[ ... -
JSP中的EL表达式详细介绍
2016-05-10 13:40 343http://blog.csdn.net/meiyalei/a ... -
解决sqoop将数据导入mysql乱码
2015-10-26 17:14 1319mysql 字符集修改: (5.5以前系统)#vim /etc ... -
linux tomcat java.lang.OutOfMemoryError
2013-09-18 15:42 785----------------------Linux下 ... -
转载:Apache+Tomcat集群配置负载均衡器
2012-02-09 14:52 980主 题:Apache+Tomcat集群配置负载均衡器 ... -
java 图片裁剪
2011-11-10 10:54 910web开发,前段页面上传图片进行裁剪的实例 -
java安全6
2011-10-11 16:27 1099package com.ngsn.security; ... -
java安全5
2011-09-27 10:48 523package com.ngsn.security; ... -
java安全4
2011-09-27 10:47 544package com.ngsn.security; ... -
java安全3
2011-09-27 10:47 697package com.ngsn.security; ... -
java安全2
2011-09-27 10:46 820package com.ngsn.security; ... -
java安全1
2011-09-27 10:45 724package com.ngsn.security; ... -
Spring 2.5-applicationContext.xml提示信息的配置
2011-08-24 14:47 1485如果在applicationContext.xml里打“ Pr ...
相关推荐
在渗透测试中遇到json数据一般都会测试下有没有反序列化,然而JSON库有Fastjson,JackJson,Gson等等,那么怎么判断后端不是Fastjson呢?可以构造特定的payload来进行探测分析
这是本人写方便复习,该资源并没有什么用处
主要针对常用的json工具Gson,jackson,fastjson进行性能测试,一个完整的工程,包含测试类、测试结论,以及三个工具包的jar文件。可以直接在eclipse中运行。具体版本如下: fastjson-1.1.28.jar gson-1.7.1.jar ...
fastjson与protobuf,自己测试用代码
采用开源项目fastjson做的小测试,fastjson确实不错,怪不得2012年被评为最受欢迎开源项目之一
Fastjson是一个Java语言编写的高性能功能完善的JSON库。 高性能: fastjson采用独创的算法,将parse的速度提升到极致,超过所有...fastjson有超过1500个testcase,每次构建都会跑一遍,丰富的测试场景保证了功能稳定。
赠送jar包:fastjson-1.2.54.jar; 赠送原API文档:fastjson-1.2.54-javadoc.jar; 赠送源代码:fastjson-1.2.54-sources.jar; 赠送Maven依赖信息文件:fastjson-1.2.54.pom; 包含翻译后的API文档:fastjson-...
fastjson-1.2.83.jar下载,fastjson是阿里巴巴的开源JSON解析库,可以解析JSON格式的字符串,支持将Java Bean序列化为JSON字符串,也支持从JSON字符串反序列化到JavaBean。fastjson采用全新的JSON解析算法,运行速度极快...
Fastjson 1.2.80 及之前版本使用黑白名单用于防御反序列化漏洞,经研究该防御策略在特定条件下可绕过默认 autoType 关闭限制,攻击远程服务器,风险影响较大。建议 Fastjson 用户尽快采取安全措施保障系统安全
赠送jar包:fastjson-1.2.72.jar; 赠送原API文档:fastjson-1.2.72-javadoc.jar; 赠送源代码:fastjson-1.2.72-sources.jar; 赠送Maven依赖信息文件:fastjson-1.2.72.pom; 包含翻译后的API文档:fastjson-1.2....
fastjson-1.1.35.jar ,fastjson-1.1.36.jar ,fastjson-1.1.37.jar ,fastjson-1.1.44.jar ,fastjson-1.2.3.jar,fastjson-1.2.4.jar
springboot2.0整合fastjson实例配置,在测试类中有各种fastjson的使用,序列化反序列化,以及jsonObject与jsonarray的使用,具体测试方法在测试类中
赠送jar包:fastjson-1.2.78.jar; 赠送原API文档:fastjson-1.2.78-javadoc.jar; 赠送源代码:fastjson-1.2.78-sources.jar; 赠送Maven依赖信息文件:fastjson-1.2.78.pom; 包含翻译后的API文档:fastjson-1.2....
Alibaba Fastjson Jar包官方版是可以帮助使用Fastjson功能的Fastjson jar包,Fastjson是一个Java语言编写的高性能功能完善的JSON库,当然必备Alibaba Fastjson Jar包官方版。
Android Studio FastJSON小示例,对应博文地址: http://blog.csdn.net/djstavaV/article/details/48785801
fastJSON 版本 v2.1.18
fastjson 的一个小例子,里面是我博客中的代码, http://blog.csdn.net/yunxiaoxiaoyun/article/details/16811973
阿里巴巴 JSON解析jar包 fastjson,测试表明,fastjson具有极快的性能,超越任其他的Java Json parser 更新时间 2015年10月 27日
springboot 使用spring cache缓存 和 使用fastjson配置redis系列化,springboot 使用spring cache缓存 和 使用fastjson配置redis系列化,springboot 使用spring cache缓存 和 使用fastjson配置redis系列化,springboot ...
实现json转换,fastjson json json转换,可以帮助开发中涉及json格式处理的程序猿。