Releases: alibaba/fastjson2
fastjson 2.0.8发布
1. FASTJSON 2.0介绍
FASTJSON v2
是FASTJSON
项目的重要升级,目标是为下一个十年提供一个高性能的JSON
库。通过同一套API
,
- 支持
JSON/JSONB
两种协议,JSONPath
是一等公民。 - 支持全量解析和部分解析。
- 支持
Java
服务端、客户端Android
、大数据场景。 - 支持
Kotlin
https://alibaba.github.io/fastjson2/kotlin_cn - 支持
JSON Schema
https://alibaba.github.io/fastjson2/json_schema_cn - 支持
Android 8+
(2.0.8.android) - 支持
Graal Native-Image
(2.0.8.graal)
2. FASTJSON 2.0.8版本 介绍
经过很多用户在生产环境验证,2.0.8完全生产可用。对fastjson 1.x也有很好的兼容性,如果不想改代码的同学,可以尝试直接使用2.0.8的兼容包升级,兼容包是计划长期维护的,如果发现问题提issue反馈。
Issues
- 修改LocalDateTime的缺省序列化格式为"yyyy-MM-dd HH:mm:ss",LocalDate的缺省序列化格式为"yyyy-MM-dd",LocalTime的缺省序列化格式为"HH:mm:ss",没有特定需求时,不需要做配置定制序列化。 #463 #459
- Date对象反序列化支持输入空字符串识别为null #467 #504 #493
- 修复某些场景日期类型配置JSONField.format无效的问题 #468 #495
- 兼容包支持ParserConfig配置propertyNamingStrategy #505
- 修复TypeReference传入参数无法正确解析的问题 #501 #474
- 修复BigDecimal类型反序列化输入科学计数法数值结果不对的问题 #492
- 兼容包支持Feature. UseNativeJavaObject #488
- 修复JSONPath在多层嵌套读取结果不对的问题 #487
- 修复兼容包JSON.parseObject不支持输入空置的问题 #482
- 修复mongo GeoJsonPoint类型的支持 bug #483
- 修复JSONPath设置多层节点不存在时不生效的问题 #476
- JSONArray保留toJSONString方法,方便升级,提升兼容性
- JSON.parseObject方法支持InputStream和Reader输入 #103
- 修复JSONPath对"$"结果返回不对的问题
- 修复JSONWriter.Feature.IgnoreNoneSerializable对rootObject不生效的问题 #477
- 新增支持ContextNameFilter/ContextValueFilter #484
- 修复对象数组类型字段反序列化报错的问题 #464
- 修复PropertyFilter导致输出Null的问题 #471
3. MAVEN依赖配置
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.8</version>
</dependency>
- GraalVM版本
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.8.graal</version>
</dependency>
- Android版本
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.8.android</version>
</dependency>
- 1.x 兼容版本
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.8</version>
</dependency>
相关链接
- 相关issue 25个 https://github.com/alibaba/fastjson2/milestone/7
- 代码tag https://github.com/alibaba/fastjson2/releases/tag/2.0.8
- 标准版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.8/
- graal支持版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.8.graal/ (仅在GraalVM 22.1 JDK17上做过验证)
- android版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.8.android/
- 1.x兼容版本 https://repo1.maven.org/maven2/com/alibaba/fastjson/2.0.8/
fastjson 2.0.7发布,修复BUG提升兼容性
1. FASTJSON 2.0介绍
FASTJSON 2.0是FASTJSON项目的重要升级,目标是为下一个十年提供一个高性能的JSON库,同一套API支持JSON/JSONB两种协议,JSONPath是一等公民,支持全量解析和部分解析,支持Java服务端、客户端Android、大数据场景。
- FASJTONS2项目地址 https://github.com/alibaba/fastjson2
- 使用介绍 https://alibaba.github.io/fastjson2/
- FASTJSON 2性能有了很大提升,具体性能数据看这里 https://github.com/alibaba/fastjson2/wiki/benchmark_2.0.7_aarch64
- FASTJSON 2的AutoType没有内置白名单,更安全 https://alibaba.github.io/fastjson2/autotype_cn
- 支持JSONSchema https://alibaba.github.io/fastjson2/json_schema_cn
- 支持JDK14 Record
- 支持GraalVM Native-Image
2. FASTJSON 2.0.7版本 介绍
经过很多用户在生产环境验证,2.0.7已经具备生产可用的能力,但由于是初期版本,使用到生产还需要仔细观察验证,如果遇到问题反馈提issue到 https://github.com/alibaba/fastjson2/issues 。
2.0.7继续提升的兼容性,如果不想改代码的同学,可以尝试直接使用2.0.7的兼容包升级,兼容包是计划长期维护的,如果发现问题提issue反馈。
Issues
- 修复了部分场景JSON.isValid方法在某些场景不能识别非法JSON格式的问题 #410
- 修复JSONPath.set在已有值存在时缺省采用DuplicateKeyValueAsArray行为的问题 #431
- 修复JSONPath.set在父层次对象不存在时结果不对的问题 #424
- 提升了fastjson 1.x的兼容性 #432
- 修复了filter导致WriteClassName失效的问题 #411
- 修复了不能LocalDate/LocalTime不能智能匹配日期格式的问题 #LocalDate #356 #416 #425
- 优化常见日期类型的序列化和反序列化性能 #137
- 修复了List类型不支持非数组单个元素输入的问题 #409 #426
- 修复某些场景Exception类型字段不能正确反序列化的问题 #362
- 修复了WriteClassName启用后,Byte/Short/Float/Double/Long/Date在某些场景反序列化类型丢失的问题 #412 #381 #454
- 修复了报错是文案不友好的问题 #414
- 修复了日期类型对日期格式支持不完整的问题 #413
- 修复了Float/Double序列化NaN/INFINITY/NEGATIVE_INFINITY不以null输出的问题 #423
- BigDecimal类型支持MongoDB Decimal128格式 #427
- 修复boolean不支持空字符串输入的问题 #429
- 新增JSONWriter.Feature.NotWriteEmptyArray,支持序列化时不输出空集合和空数组
- 修复不可见字符输出格式不对的问题 #435
- 修复JSONWriter.Feature.FieldBased打开时JSONField在某些类型字段上不生效的问题 #445
- 提升fastjson 1.x API的兼容性 #446
- 修复某些场景Kotlin序列化Map类型报错的问题 #440
2.1 定制序列化介绍
FASTJSON2支持完善的定制序列化反序列化功能
- Feature介绍 https://alibaba.github.io/fastjson2/features_cn
- Annotation介绍 https://alibaba.github.io/fastjson2/annotations_cn
- 使用Mixin注入Anntation定制序列化和反序列化 https://alibaba.github.io/fastjson2/mixin_cn
- 实现ObjectWriter和ObjectReader实现定制序列化和反序列化 https://alibaba.github.io/fastjson2/register_custom_reader_writer_cn
3. MAVEN依赖配置
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.7</version>
</dependency>
- GraalVM版本
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.7.graal</version>
</dependency>
- Android版本
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.7.android</version>
</dependency>
- 1.x 兼容版本
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.7</version>
</dependency>
相关链接
- 相关issue 27个 https://github.com/alibaba/fastjson2/milestone/6
- 代码tag https://github.com/alibaba/fastjson2/releases/tag/2.0.7
- 标准版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.7/
- graal支持版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.7.graal/ (仅在GraalVM 22.1 JDK17上做过验证)
- android版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.7.android/
- 1.x兼容版本 https://repo1.maven.org/maven2/com/alibaba/fastjson/2.0.7/
fastjson 2.0.6发布,修复BUG提升兼容性
1. FASTJSON 2.0介绍
FASTJSON 2.0是FASTJSON项目的重要升级,目标是为下一个十年提供一个高性能的JSON库,同一套API支持JSON/JSONB两种协议,JSONPath是一等公民,支持全量解析和部分解析,支持Java服务端、客户端Android、大数据场景。
- FASJTONS2项目地址 https://github.com/alibaba/fastjson2
- 使用介绍 https://alibaba.github.io/fastjson2/
- FASTJSON 2性能有了很大提升,具体性能数据看这里 https://alibaba.github.io/fastjson2/benchmark_cn
- FASTJSON 2的AutoType没有内置白名单,更安全 https://alibaba.github.io/fastjson2/autotype_cn
- 支持JSONSchema https://alibaba.github.io/fastjson2/json_schema_cn
- 支持JDK14 Record
- 支持GraalVM Native-Image
2. FASTJSON 2.0.6版本 介绍
经过众多勇敢热心同学的验证,2.0.6已经具备生产可用的能力,但由于是初期版本,使用到生产还需要仔细观察验证,如果遇到问题反馈提issue到 https://github.com/alibaba/fastjson2/issues 。
2.0.6的兼容性也有很大改善,如果不想改代码的同学,可以尝试直接使用2.0.6的兼容包升级。
Issues
- 修复getObject方法不能自动识别非camalCase fieldName的问题 #402
- 修复JSONB格式反序列化List报错的问题 #385
- 新增加JSONReader.Feature DuplicateKeyValueAsArray,重复属性不是替换而是组合成数组 #379 #263
- 修复ReadOnly Collection字段反序列化某些场景抛空指针的问题 #397
- 修复fastjson 1.x兼容API中Feature.OrderedField不生效的问题 #394
- 修复fastjson 1.x兼容API中返回fastjson2的JSONArray导致类型不匹配的问题 #399
- 修复JSONB格式反序列化使用com.google.common.collect.Lists.transform报错的问题 #400
- 修复不支持fastjson 1.x JSONField.jsonDirect配置的问题 #398
- 修复WriteNulls & NullAsDefaultValue输出结果不对的问题 #372 #391
- 修复某些场景配置JSONField.format='392'不生效的问题 #392
- 修复某些API不能支持null和空字符串输入的问题 #389
- 修复集成spring-doc导致文档无法显示的问题 #387
- 修复graalvm编译native-image报错,框架使用quarkus报错的问题 #386
- 修复兼容fastjson 1.x API不支持JSONField.deserializeUsing的问题 #388
- 新增JSONReader.Feature AllowUnQuotedFieldNames,同时兼容fastjson 1.x #383
- 新增反序列化支持配置代替JSONObject/JSONArray的支持 #384
- 修复JSONField.format在context配置format后优先级不对的问题 #380
- 修复某些场景处理引用不对的问题 #377 #378
- 修复Android兼容的问题 #375
- 修复无法反序列化Class<?>对象的问题 #369
- 修复Android下某些场景kotlin报错的问题 #370
2.1 定制序列化介绍
FASTJSON2支持完善的定制序列化反序列化功能
- Feature介绍 https://alibaba.github.io/fastjson2/features_cn
- Annotation介绍 https://alibaba.github.io/fastjson2/annotations_cn
- 使用Mixin注入Anntation定制序列化和反序列化 https://alibaba.github.io/fastjson2/mixin_cn
- 实现ObjectWriter和ObjectReader实现定制序列化和反序列化 https://alibaba.github.io/fastjson2/register_custom_reader_writer_cn
3. MAVEN依赖配置
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.6</version>
</dependency>
- GraalVM版本
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.6.graal</version>
</dependency>
- Android版本
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.6.android</version>
</dependency>
- 1.x 兼容版本
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.6</version>
</dependency>
相关链接
- 相关issue 29个 https://github.com/alibaba/fastjson2/milestone/5
- 代码tag https://github.com/alibaba/fastjson2/releases/tag/2.0.6
- 标准版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.6/
- graal支持版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.6.graal/ (仅在GraalVM 22.1 JDK17上做过验证)
- android版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.6.android/
- 1.x兼容版本 https://repo1.maven.org/maven2/com/alibaba/fastjson/2.0.6/
fastjson 2.0.5发布
1. FASTJSON 2.0介绍
FASTJSON 2.0是FASTJSON项目的重要升级,目标是为下一个十年提供一个高性能的JSON库,同一套API支持JSON/JSONB两种协议,JSONPath是一等公民,支持全量解析和部分解析,支持Java服务端、客户端Android、大数据场景。
- FASJTONS2项目地址 https://github.com/alibaba/fastjson2
- 使用介绍 https://alibaba.github.io/fastjson2/
- FASTJSON 2性能有了很大提升,具体性能数据看这里 https://alibaba.github.io/fastjson2/benchmark_cn
- FASTJSON 2的AutoType没有内置白名单,更安全 https://alibaba.github.io/fastjson2/autotype_cn
- 支持JSONSchema https://alibaba.github.io/fastjson2/json_schema_cn
- 支持JDK14 Record
- 支持GraalVM Native-Image
2. FASTJSON 2.0.5版本 介绍
经过众多勇敢热心同学的验证,2.0.5已经具备生产可用的能力,但由于是初期版本,使用到生产还需要仔细观察验证,如果遇到问题反馈提issue到 https://github.com/alibaba/fastjson2/issues 。
2.0.5的兼容性也有很大改善,如果不想改代码的同学,可以尝试直接使用2.0.5的兼容包升级。
- 修复JSONB不打开fieldBase时,反序列化java.util.Arrays$ArrayList报错的问题 #341
- 修复字符串在不匹配字段存在'\uxxxx'字符报错的问题 #371
- 增加对fastjson 1.x Feature.OrderedField的兼容 #334
- 修复LocalDate使用dateFormat'yyyy-MM-dd HH:mm:ss'报错的问题 #363
- 增加对JSONReader.Feature和JSONWriter.Feature的全局配置 #361
- 修复从1.x升级到2.x不能识别'org.springframework.security.core.GrantedAuthority'的问题 #354
- 增加BeforeFilter/AfterFilter,兼容1.x API #359
- 增加JSONReader.Feature TrimString,支持反序列化对输入的String做trim处理 #353
- 修复配置ValueFilter在返回类型和输入类型不匹配时报错的问题 #351
- 修复2.0.2后错误判断导致ASM JIT不起作用的问题 #352
- 修复Android 9下报No virtual method keySet错误的问题 #350
- 修复配置Filter并且存在Map类型空置报错的问题 #347
- 修复toJSONString方法缺失导致rocketmq升级2.x版本后报错无法启动的问题 #344
- 修复JSONArray缺失parseArray导致升级不兼容的问题
- 修复对1.xSwaggerJsonSerializer和ObjectSerializer/ObjectDeserializer的支持 #324
- 修复在sofaboot中升级1.x到2.x不兼容的问题 #332
- 修复JSONObject.getObject方法传入数据类型报错的问题 #326
- 修复JSONArray.toList方法不支持简单类型的问题 #316 #296
- 修复对File类序列化不内置支持的问题 #312
- 修复JSONField配置JSONWriter.Feature.WriteEnumsUsingName 不起作用的问题 #314
- 修复JSONWriter.Feature.ReferenceDetection在序列化List字段不起作用的问题 #304
- 修复错误输入字符串不报错的问题 #235
- 其他对fastjson 1.x的兼容问题
2.1 定制序列化介绍
FASTJSON2支持完善的定制序列化反序列化功能
- Feature介绍 https://alibaba.github.io/fastjson2/features_cn
- Annotation介绍 https://alibaba.github.io/fastjson2/annotations_cn
- 使用Mixin注入Anntation定制序列化和反序列化 https://alibaba.github.io/fastjson2/mixin_cn
- 实现ObjectWriter和ObjectReader实现定制序列化和反序列化 https://alibaba.github.io/fastjson2/register_custom_reader_writer_cn
3. MAVEN依赖配置
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.5</version>
</dependency>
- GraalVM版本
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.5.graal</version>
</dependency>
- Android版本
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.5.android</version>
</dependency>
- 1.x 兼容版本
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.5</version>
</dependency>
相关链接
- 相关issue 15个 https://github.com/alibaba/fastjson2/milestone/4
- 代码tag https://github.com/alibaba/fastjson2/releases/tag/2.0.5
- 标准版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.5/
- graal支持版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.5.graal/ (仅在GraalVM 22.1 JDK17上做过验证)
- android版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.5.android/
- 1.x兼容版本 https://repo1.maven.org/maven2/com/alibaba/fastjson/2.0.5/
fastjson 2.0.4发布
1. FASTJSON 2.0介绍
FASTJSON 2.0是FASTJSON项目的重要升级,目标是为下一个十年提供一个高性能的JSON库,同一套API支持JSON/JSONB两种协议,JSONPath是一等公民,支持全量解析和部分解析,支持Java服务端、客户端Android、大数据场景。
- FASJTONS2项目地址 https://github.com/alibaba/fastjson2
- 使用介绍 https://alibaba.github.io/fastjson2/
- FASTJSON 2性能有了很大提升,具体性能数据看这里 https://alibaba.github.io/fastjson2/benchmark_cn
- FASTJSON 2的AutoType没有内置白名单,更安全 https://alibaba.github.io/fastjson2/autotype_cn
- 支持JSONSchema https://alibaba.github.io/fastjson2/json_schema_cn
- 支持JDK14 Record
- 支持GraalVM Native-Image
2. FASTJSON 2.0.4版本 介绍
经过多个热心同学的验证,2.0.4已经具备生产可用的能力,但由于是初期版本,使用到生产还需要仔细观察验证,如果遇到问题反馈提issue到 https://github.com/alibaba/fastjson2/issues
- 更好兼容fastjson 1.x #248 #255 #274 #269 #287
- 对JDK17更好支持 #265
- 修复对反序列化多ClassLoader类冲突的问题 #252
- 内置支持GeoJson #256
- 提升对kotlin的支持 #276
- JSONObject修复泛型编译警告问题 #257 #282
- 支持json schema #239 ,相关介绍看这里 https://alibaba.github.io/fastjson2/son_schema_cn
2.1 定制序列化介绍
FASTJSON2支持完善的定制序列化反序列化功能
- Feature介绍 https://alibaba.github.io/fastjson2/features_cn
- Annotation介绍 https://alibaba.github.io/fastjson2/annotations_cn
- 使用Mixin注入Anntation定制序列化和反序列化 https://alibaba.github.io/fastjson2/mixin_cn
- 实现ObjectWriter和ObjectReader实现定制序列化和反序列化 https://alibaba.github.io/fastjson2/register_custom_reader_writer_cn
3. MAVEN依赖配置
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.4</version>
</dependency>
- GraalVM版本
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.4.graal</version>
</dependency>
- Android版本
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.4.android</version>
</dependency>
- 1.x 兼容版本
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.4</version>
</dependency>
相关链接
- 相关issue 17个 https://github.com/alibaba/fastjson2/milestone/3
- 代码tag https://github.com/alibaba/fastjson2/releases/tag/2.0.4
- 标准版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.4/
- graal支持版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.4.graal/ (仅在GraalVM 22.1 JDK17上做过验证)
- android版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.4.android/
- 1.x兼容版本 https://repo1.maven.org/maven2/com/alibaba/fastjson/2.0.4/
fastjson 2.0.3发布
1. FASTJSON 2.0介绍
FASTJSON 2.0是FASTJSON项目的重要升级,目标是为下一个十年提供一个高性能的JSON库,同一套API支持JSON/JSONB两种协议,JSONPath是一等公民,支持全量解析和部分解析,支持Java服务端、客户端Android、大数据场景。
- FASJTONS2项目地址 https://github.com/alibaba/fastjson2
- 使用介绍 https://github.com/alibaba/fastjson2/wiki/fastjson2_intro_cn
- FASTJSON 2性能有了很大提升,具体性能数据看这里 https://github.com/alibaba/fastjson2/wiki/fastjson_benchmark
- FASTJSON 2的AutoType没有内置白名单,更安全 https://github.com/alibaba/fastjson2/wiki/fastjson2_autotype_cn
2. FASTJSON 2.0.3版本 介绍
经过多个热心同学的验证,2.0.3已经基本具备生产可用的能力,但由于是初期版本,使用到生产还需要仔细观察验证。
- 更好兼容fastjson 1.x
- 支持JDK 14引入的Record
- 支持GraalVM native-image
- 完善了扩展机制
- 增强了对JSONPath的支持
- 兼容jackson常用Annotation,方便用户从jackson切换到fastjson2
- 提升了转义符很多的场景的反序列化性能
2.1 定制序列化介绍
FASTJSON2支持完善的定制序列化反序列化功能
- Feature介绍 https://github.com/alibaba/fastjson2/wiki/Features_cn
- Annotation介绍 https://github.com/alibaba/fastjson2/wiki/fastjson2_annotations
- 使用Mixin注入Anntation定制序列化和反序列化 https://github.com/alibaba/fastjson2/wiki/mixin_cn
- 实现ObjectWriter和ObjectReader实现定制序列化和反序列化 https://github.com/alibaba/fastjson2/wiki/register_custom_reader_writer_cn
3. MAVEN依赖配置
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.3</version>
</dependency>
- GraalVM版本
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.3.graal</version>
</dependency>
- Android版本
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.3.android</version>
</dependency>
相关链接
- 相关issue 31个 https://github.com/alibaba/fastjson2/milestone/2
- 代码tag https://github.com/alibaba/fastjson2/releases/tag/2.0.3
- 标准版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.3/
- graal支持版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.3.graal/ (仅在GraalVM 22.1 JDK17上做过验证)
- android版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.3.android/
fastjson 2.0.2发布
1. FASTJSON 2.0介绍
FASTJSON 2.0是FASTJSON项目的重要升级,目标是为下一个十年提供一个高性能的JSON库,同一套API支持JSON/JSONB两种协议,JSONPath是一等公民,支持全量解析和部分解析,支持Java服务端、客户端Android、大数据场景。
- FASJTONS2项目地址 https://github.com/alibaba/fastjson2
- 使用介绍 https://github.com/alibaba/fastjson2/wiki/fastjson2_intro_cn
- FASTJSON 2性能有了很大提升,具体性能数据看这里 https://github.com/alibaba/fastjson2/wiki/fastjson_benchmark
2. FASTJSON 2.0.2版本 介绍
这个版本主要是提升对fastjson 1.x的兼容性,修复2.0.1版本发现的一些bug。经过多个热心同学的验证,已经初步具备生产可用的能力,但由于初期版本,使用到生产还需要仔细观察验证。
3. MAVEN依赖配置
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.2</version>
</dependency>
相关链接
- 相关issue 56个 https://github.com/alibaba/fastjson2/milestone/1?closed=1
- 代码tag https://github.com/alibaba/fastjson2/releases/tag/2.0.2
- 标准版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.2/
- graal支持版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.2.graal/
- android版本 https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/2.0.2.android/
fastjson 2.0.1发布
1. FASTJSON 2.0介绍
FASTJSON 2.0是FASTJSON项目的重要升级,目标是为下一个十年提供一个高性能的JSON库,同一套API支持JSON/JSONB两种协议,JSONPath是一等公民,支持全量解析和部分解析,支持Java服务端、客户端Android、大数据场景。
- FASJTONS2代码 https://github.com/alibaba/fastjson2/releases/tag/2.0.1
- JSONB格式文档 https://github.com/alibaba/fastjson2/wiki/jsonb_format_cn
- FASTJSON 2性能有了很大提升,具体性能数据看这里 https://github.com/alibaba/fastjson2/wiki/fastjson_benchmark
2. 使用前准备
2.1 Maven依赖
在fastjson 2.0中,groupId和1.x不一样,是com.alibaba.fastjson2
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.1</version>
</dependency>
https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/
2.2
如果原来使用fastjson 1.2.x版本,可以使用兼容包,兼容包不能保证100%兼容,请仔细测试验证,发现问题请及时反馈。
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.1</version>
</dependency>
2.2 常用类和方法
在fastjson 2.0中,package和1.x不一样,是com.alibaba.fastjson2。如果你之前用的是fastjson1,大多数情况直接更包名就即可。
package com.alibaba.fastjson2;
class JSON {
// 将字符串解析成JSONObject
static JSONObject parseObject(String str);
// 将字符串解析成JSONArray
static JSONArray parseArray(String str);
// 将字符串解析成Java对象
static T parseObject(byte[] utf8Bytes, Class<T> objectClass);
// 将Java对象输出成字符串
static String toJSONString(Object object);
// 将Java对象输出成UT8编码的byte[]
static byte[] toJSONBytes(Object object);
}
class JSONB {
// 将jsonb格式的byte[]解析成Java对象
static T parseObject(byte[] jsonbBytes, Class<T> objectClass);
// 将Java对象输出成jsonb格式的byte[]
static byte[] toBytes(Object object);
}
class JSONObject {
Object get(String key);
int getIntValue(String key);
Integer getInteger(String key);
long getLongValue(String key);
Long getLong(String key);
T getObject(String key, Class<T> objectClass);
// 将JSONObject对象转换为Java对象
T toJavaObject(Class<T> objectClass);
}
class JSONArray {
Object get(int index);
int getIntValue(int index);
Integer getInteger(int index);
long getLongValue(int index);
Long getLong(int index);
T getObject(int index, Class<T> objectClass);
}
class JSONPath {
// 构造JSONPath
static JSONPath of(String path);
// 根据path直接解析输入,会部分解析优化,不会全部解析
Object extract(JSONReader jsonReader);
// 根据path对对象求值
Object eval(Object rootObject);
}
class JSONReader {
// 构造基于String输入的JSONReader
static JSONReader of(String str);
// 构造基于ut8编码byte数组输入的JSONReader
static JSONReader of(byte[] utf8Bytes);
// 构造基于char[]输入的JSONReader
static JSONReader of(char[] chars);
// 构造基于json格式byte数组输入的JSONReader
static JSONReader ofJSONB(byte[] jsonbBytes)
}
3. 读取JSON对象
String str = "{\"id\":123}";
JSONObject jsonObject = JSON.parseObject(str);
int id = jsonObject.getIntValue("id");
String str = "[\"id\", 123]";
JSONArray jsonArray = JSON.parseArray(str);
String name = jsonArray.getString(0);
int id = jsonArray.getIntValue(1);
4. 将JavaBean对象生成JSON
4.1 将JavaBean对象生成JSON格式的字符串
class Product {
public int id;
public String name;
}
Product product = new Product();
product.id = 1001;
product.name = "DataWorks";
JSON.toJSONString(product);
// 生成如下的结果
{
"id" : 1001,
"name" : "DataWorks"
}
JSON.toJSONString(product, JSONWriter.Feature.BeanToArray);
// 生成如下的结果
[123, "DataWorks"]
4.2 将JavaBean对象生成UTF8编码的byte[]
Product product = ...;
byte[] utf8JSONBytes = JSON.toJSONBytes(product);
4.3 将JavaBean对象生成JSONB格式的byte[]
Product product = ...;
byte[] jsonbBytes = JSONB.toBytes(product);
byte[] jsonbBytes = JSONB.toBytes(product, JSONWriter.Feature.BeanToArray);
5. 读取JavaBean
5.1 将字符串读取成JavaBean
String str = "{\"id\":123}";
Product product = JSON.parseObject(str, Product.class);
5.2 将UTF8编码的byte[]读取成JavaBean
byte[] utf8Bytes = "{\"id\":123}".getBytes(StandardCharsets.UTF_8);
Product product = JSON.parseObject(utf8Bytes, Product.class);
5.3 将JSONB数据读取成JavaBean
byte[] jsonbBytes = ...
Product product = JSONB.parseObject(jsonbBytes, Product.class);
Product product = JSONB.parseObject(jsonbBytes, Product.class, JSONReader.Feature.SupportBeanArrayMapping);
6. 使用JSONPath
6.1 使用JSONPath部分读取数据
String str = ...;
JSONPath path = JSONPath.of("$.id"); // 缓存起来重复使用能提升性能
JSONReader parser = JSONReader.of(str);
Object result = path.extract(parser);
6.2 使用JSONPath读取部分utf8Bytes的数据
byte[] utf8Bytes = ...;
JSONPath path = JSONPath.of("$.id"); // 缓存起来重复使用能提升性能
JSONReader parser = JSONReader.of(utf8Bytes);
Object result = path.extract(parser);
6.3 使用JSONPath读取部分jsonbBytes的数据
byte[] jsonbBytes = ...;
JSONPath path = JSONPath.of("$.id"); // 缓存起来重复使用能提升性能
JSONReader parser = JSONReader.ofJSONB(jsonbBytes); // 注意,这是利用ofJSONB方法
Object result = path.extract(parser);
fastjson 2.0.0发布
1. FASTJSON 2.0介绍
FASTJSON 2.0是FASTJSON项目的重要升级,目标是为下一个十年提供一个高性能的JSON库,同一套API支持JSON/JSONB两种协议,JSONPath是一等公民,支持全量解析和部分解析,支持Java服务端、客户端Android、大数据场景。
- FASJTONS2代码 https://github.com/alibaba/fastjson2/releases/tag/2.0.0
- JSONB格式文档 https://github.com/alibaba/fastjson2/wiki/jsonb_format_cn
- FASTJSON 2性能有了很大提升,具体性能数据看这里 https://github.com/alibaba/fastjson2/wiki/fastjson_benchmark
2. 使用前准备
2.1 Maven依赖
在fastjson 2.0中,groupId和1.x不一样,是com.alibaba.fastjson2
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.0</version>
</dependency>
https://repo1.maven.org/maven2/com/alibaba/fastjson2/fastjson2/
2.2
如果原来使用fastjson 1.2.x版本,可以使用兼容包,兼容包不能保证100%兼容,请仔细测试验证,发现问题请及时反馈。
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.0</version>
</dependency>
2.2 常用类和方法
在fastjson 2.0中,package和1.x不一样,是com.alibaba.fastjson2。如果你之前用的是fastjson1,大多数情况直接更包名就即可。
package com.alibaba.fastjson2;
class JSON {
// 将字符串解析成JSONObject
static JSONObject parseObject(String str);
// 将字符串解析成JSONArray
static JSONArray parseArray(String str);
// 将字符串解析成Java对象
static T parseObject(byte[] utf8Bytes, Class<T> objectClass);
// 将Java对象输出成字符串
static String toJSONString(Object object);
// 将Java对象输出成UT8编码的byte[]
static byte[] toJSONBytes(Object object);
}
class JSONB {
// 将jsonb格式的byte[]解析成Java对象
static T parseObject(byte[] jsonbBytes, Class<T> objectClass);
// 将Java对象输出成jsonb格式的byte[]
static byte[] toBytes(Object object);
}
class JSONObject {
Object get(String key);
int getIntValue(String key);
Integer getInteger(String key);
long getLongValue(String key);
Long getLong(String key);
T getObject(String key, Class<T> objectClass);
// 将JSONObject对象转换为Java对象
T toJavaObject(Class<T> objectClass);
}
class JSONArray {
Object get(int index);
int getIntValue(int index);
Integer getInteger(int index);
long getLongValue(int index);
Long getLong(int index);
T getObject(int index, Class<T> objectClass);
}
class JSONPath {
// 构造JSONPath
static JSONPath of(String path);
// 根据path直接解析输入,会部分解析优化,不会全部解析
Object extract(JSONReader jsonReader);
// 根据path对对象求值
Object eval(Object rootObject);
}
class JSONReader {
// 构造基于String输入的JSONReader
static JSONReader of(String str);
// 构造基于ut8编码byte数组输入的JSONReader
static JSONReader of(byte[] utf8Bytes);
// 构造基于char[]输入的JSONReader
static JSONReader of(char[] chars);
// 构造基于json格式byte数组输入的JSONReader
static JSONReader ofJSONB(byte[] jsonbBytes)
}
3. 读取JSON对象
String str = "{\"id\":123}";
JSONObject jsonObject = JSON.parseObject(str);
int id = jsonObject.getIntValue("id");
String str = "[\"id\", 123]";
JSONArray jsonArray = JSON.parseArray(str);
String name = jsonArray.getString(0);
int id = jsonArray.getIntValue(1);
4. 将JavaBean对象生成JSON
4.1 将JavaBean对象生成JSON格式的字符串
class Product {
public int id;
public String name;
}
Product product = new Product();
product.id = 1001;
product.name = "DataWorks";
JSON.toJSONString(product);
// 生成如下的结果
{
"id" : 1001,
"name" : "DataWorks"
}
JSON.toJSONString(product, JSONWriter.Feature.BeanToArray);
// 生成如下的结果
[123, "DataWorks"]
4.2 将JavaBean对象生成UTF8编码的byte[]
Product product = ...;
byte[] utf8JSONBytes = JSON.toJSONBytes(product);
4.3 将JavaBean对象生成JSONB格式的byte[]
Product product = ...;
byte[] jsonbBytes = JSONB.toBytes(product);
byte[] jsonbBytes = JSONB.toBytes(product, JSONWriter.Feature.BeanToArray);
5. 读取JavaBean
5.1 将字符串读取成JavaBean
String str = "{\"id\":123}";
Product product = JSON.parseObject(str, Product.class);
5.2 将UTF8编码的byte[]读取成JavaBean
byte[] utf8Bytes = "{\"id\":123}".getBytes(StandardCharsets.UTF_8);
Product product = JSON.parseObject(utf8Bytes, Product.class);
5.3 将JSONB数据读取成JavaBean
byte[] jsonbBytes = ...
Product product = JSONB.parseObject(jsonbBytes, Product.class);
Product product = JSONB.parseObject(jsonbBytes, Product.class, JSONReader.Feature.SupportBeanArrayMapping);
6. 使用JSONPath
6.1 使用JSONPath部分读取数据
String str = ...;
JSONPath path = JSONPath.of("$.id"); // 缓存起来重复使用能提升性能
JSONReader parser = JSONReader.of(str);
Object result = path.extract(parser);
6.2 使用JSONPath读取部分utf8Bytes的数据
byte[] utf8Bytes = ...;
JSONPath path = JSONPath.of("$.id"); // 缓存起来重复使用能提升性能
JSONReader parser = JSONReader.of(utf8Bytes);
Object result = path.extract(parser);
6.3 使用JSONPath读取部分jsonbBytes的数据
byte[] jsonbBytes = ...;
JSONPath path = JSONPath.of("$.id"); // 缓存起来重复使用能提升性能
JSONReader parser = JSONReader.ofJSONB(jsonbBytes); // 注意,这是利用ofJSONB方法
Object result = path.extract(parser);