Skip to content

Commit

Permalink
修改文档的拼写错误。
Browse files Browse the repository at this point in the history
  • Loading branch information
MoshiCoCo authored and wenshao committed Sep 27, 2022
1 parent b6dcecd commit 3b99622
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 60 deletions.
12 changes: 6 additions & 6 deletions docs/annotations_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
JSONField是作用在Field、Method、Parameter上的Annotation,可以用来指定序列化字段的顺序、名字、格式、是否忽略、配置JSONReader/JSONWriter的Features等。

### 1.1 定制名字序列化和反序列化
可以通过JSONField.name来配置序列化输出的字段名和反序列化是映射的字段名
可以通过JSONField.name来配置序列化输出的字段名和反序列化是映射的字段名
* 配置在public field上
```java
public class A {
Expand All @@ -27,7 +27,7 @@ public class A {
```

### 1.2 配置字段输出和反序列化的格式
在Date类型的字段,经常需要用定制的格式做序列化和反序列化,可以通过JSONField.format来做配置
针对Date类型的字段,经常需要用定制的日期格式进行序列化和反序列化,可以通过JSONField.format来配置自定义日期格式
```java
public class VO {
// 配置date序列化和反序列使用yyyyMMdd日期格式
Expand All @@ -48,15 +48,15 @@ public class VO {
```

* 配置反序列化忽略特定字段
```
```java
public class VO {
@JSONField(deserialize = false)
public Date date;
}
```

### 1.4 配置字段的序列化输出的的顺序
可以通过JSONField.ordinal来配置序列化输出的顺序
可以通过JSONField.ordinal来配置序列化时输出的顺序。
```java
public static class VO {
@JSONField(ordinal = 1)
Expand All @@ -68,7 +68,7 @@ public static class VO {
```

### 1.5 配置序列化Features
可以通过JSONField.serializeFeatures来指定序列化的Feature。更多配置Features参考 [https://alibaba.github.io/fastjson2/features_cn](https://alibaba.github.io/fastjson2/features_cn)
可以通过JSONField.serializeFeatures来指定序列化的Feature。更多配置Features参考 [https://alibaba.github.io/fastjson2/features_cn](https://alibaba.github.io/fastjson2/features_cn)
```java
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter.Feature;
Expand All @@ -93,7 +93,7 @@ public static class Bean {
JSONType是配置在Class/Interface上的Annotation,可以配置改类型的所有字段的NamingStrategy、序列化和反序列化忽略的字段、JSONReader/JSONWriter的Features等。

### 2.1 配置序列化和反序列化忽略的字段
在下面的例子中,序列化输出只包括id1,忽略id2和id2
在下面的例子中,序列化输出只包括id1,忽略id2和id3。
```java
@JSONType(ignores = {"id2", "id3"})
public static class Bean {
Expand Down
14 changes: 7 additions & 7 deletions docs/autotype_cn.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# FASTJSON 2 Autotype机制介绍

## 1. AutoType功能介绍
FASTJSON支持AutoType功能,这个功能在序列化的JSON字符串中带上类型信息,在反序列化时,不需要传入类型,实现自动类型识别。
FASTJSON支持AutoType功能,这个功能会在序列化的JSON字符串中带上类型信息,在反序列化时,不需要传入类型,实现自动类型识别。

## 2. AutoType安全机制介绍
* 必须显示打开才能使用。和fastjson 1.x不一样,fastjson 1.x为了兼容有一个白名单,在fastjson 2中,没有任何白名单,也不包括任何Exception类的白名单,必须显示打开才能使用。这可以保证缺省配置下是安全的。
* 支持配置safeMode,在safeMode打开后,显式传入AutoType参数也不起作用
* 显式打开后,会经过内置黑名单过滤。该黑名单能拦截大部分常见风险,这个机制不能保证绝对安全,打开AutoType不应该在暴露在公网的场景下使用。
* 支持配置safeMode,在safeMode打开后,显示传入AutoType参数也不起作用。
* 显示打开后,会经过内置黑名单过滤。该黑名单能拦截大部分常见风险,这个机制不能保证绝对安全,打开AutoType不应该在暴露在公网的场景下使用。


## 3. AutoType功能使用介绍

### 3.1 序列化带上类型信息
序列化是带上类型信息,需要使用JSONWriter.Feature.WriteClassName。比如:
### 3.1 序列化时带上类型信息
如果需要序列化时带上类型信息,需要使用JSONWriter.Feature.WriteClassName。比如:
```java
Bean bean = ...;
String jsonString = JSON.toJSONString(bean, JSONWriter.Feature.WriteClassName);
Expand All @@ -25,13 +25,13 @@ String jsonString = JSON.toJSONString(bean, JSONWriter.Feature.WriteClassName, J
```


### 3.2 反序列化打开AutoType功能支持自动类型
### 3.2 反序列化时打开AutoType功能以支持自动类型
```java
Bean bean = (Bean) JSON.parseObject(jsonString, Object.class, JSONReader.Feature.SupportAutoType);
```

## 4. 配置safeMode
配置SafeMode是完全禁用autotype功能,如果程序中显示指定也不行
配置SafeMode会完全禁用AutoType功能,如果程序中显示指定类型,AutoType功能也不会生效。
### 4.1 JVM启动参数配置
```
-Dfastjson2.parser.safeMode=true
Expand Down
11 changes: 4 additions & 7 deletions docs/features_cn.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# 通过Features配置序列化和反序列化的行为

# 1. Feature介绍
在fastjson 2.x中,有两个Feature,分别用来配置序列化和反序列化的行为
在fastjson 2.x中,有两个Feature,分别用来配置序列化和反序列化的行为
* JSONWriter.Feature 配置序列化的行为
* JSONReader.Feature 配置反序列化的行为

Expand Down Expand Up @@ -41,7 +41,7 @@ class Model {
| SupportArrayToBean | 支持数据映射的方式 |
| InitStringFieldAsEmpty | 初始化String字段为空字符串"" |
| SupportAutoType | 支持自动类型,要读取带"@type"类型信息的JSON数据,需要显示打开SupportAutoType |
| SupportSmartMatch | 默认下是camal case精确匹配,打开这个后,能够智能识别camal/upper/pascal/snake/Kebab五中case |
| SupportSmartMatch | 默认下是camel case精确匹配,打开这个后,能够智能识别camel/upper/pascal/snake/Kebab五中case |
| UseNativeObject | 默认是使用JSONObject和JSONArray,配置后会使用LinkedHashMap和ArrayList |
| SupportClassForName | 支持类型为Class的字段,使用Class.forName。为了安全这个是默认关闭的 |
| IgnoreSetNullValue | 忽略输入为null的字段 |
Expand All @@ -55,9 +55,9 @@ class Model {
| AllowUnQuotedFieldNames | 支持不带双引号的字段名 |
| NonStringKeyAsString | 非String类型的Key当做String处理 |

# 5. JSONWrier.Feature介绍
# 5. JSONWriter.Feature介绍

| JSONWrier.Feature | 介绍 |
| JSONWriter.Feature | 介绍 |
|-----------------------------------|-----------------------------------------------------------------------------------------|
| FieldBased | 基于字段反序列化,如果不配置,会默认基于public的field和getter方法序列化。配置后,会基于非static的field(包括private)做反序列化。 |
| IgnoreNoneSerializable | 序列化忽略非Serializable类型的字段 |
Expand Down Expand Up @@ -87,6 +87,3 @@ class Model {
| NotWriteEmptyArray | 数组类型字段当length为0时不输出 |
| WriteNonStringKeyAsString | 将Map中的非String类型的Key当做String类型输出 |
| ErrorOnNoneSerializable | 序列化非Serializable对象时报错 |



80 changes: 40 additions & 40 deletions docs/features_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,47 +37,47 @@ class Model {

# 4. JSONReader.Feature

| JSONReader.Feature | Description |
| --- | --- |
| JSONReader.Feature | Description |
| --- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| FieldBased | Field-based deserialization. If not configured, it will be serialized based on public field and getter methods by default. After configuration, it will be deserialized based on non-static fields (including private). It will be safer under FieldBased configuration. |
| IgnoreNoneSerializable | Deserialization ignores fields of non-Serializable types. |
| SupportArrayToBean | Ways to support data mapping. |
| InitStringFieldAsEmpty | Initialize the String field to the empty string, e.g: "". |
| SupportAutoType | Automatic type is supported. To read JSON data with "@type" type information, you need to open SupportAutoType explicitly. |
| SupportSmartMatch | The default is camal case exact match, after opening this, it can intelligently identify the case in camal/upper/pascal/snake/Kebab. |
| UseNativeObject | The default is to use JSONObject and JSONArray, and LinkedHashMap and ArrayList will be used after configuration. |
| SupportClassForName | To support fields of type Class, use Class.forName. This is disabled by default for security. |
| IgnoreSetNullValue | Fields with null input are ignored. |
| UseDefaultConstructorAsPossible | Use the default constructor as much as possible, and use Unsafe.allocateInstance to implement this option when fieldBase is turned on and this option is not turned on. |
| UseBigDecimalForFloats | The default configuration will use BigDecimal to parse decimals, and will use Float when turned on. |
| UseBigDecimalForDoubles | The default configuration will use BigDecimal to parse decimals, and Double will be used when turned on. |
| ErrorOnEnumNotMatch | By default, if the name of the Enum does not match, it will be ignored, and an exception will be thrown if it does not match when turned on. |
| TrimString | |
| ErrorOnNotSupportAutoType | |
| DuplicateKeyValueAsArray | |
| AllowUnQuotedFieldNames | |
# 5. JSONWrier.Feature

| JSONWrier.Feature | Description |
| --- | --- |
| FieldBased | Field-based deserialization. If not configured, it will be serialized based on public field and getter methods by default. After configuration, it will be deserialized based on non-static fields (including private). |
| IgnoreNoneSerializable | Serialization ignores fields of non-Serializable types. |
| BeanToArray | Sequence the objects into an array format like [101,"XX"], which will be smaller. |
| WriteNulls| Serialize write null field |
| BrowserCompatible | Over a wide range of integers than JavaScript supports, the output is in string format. |
| NullAsDefaultValue | The null value is output as the default value, the null of the Number type is output as 0, the null output of the String type is "", and the output of the array and Collection type is []. |
| WriteBooleanAsNumber | Write true as 1 and false as 0. |
| WriteNonStringValueAsString | Write values of non-String types as Strings, excluding objects and data types. |
| WriteClassName | Write type information when serializing. |
| NotWriteRootClassName | When WriteClassName is turned on, the type information of the root object is not output. |
| IgnoreNoneSerializable | Deserialization ignores fields of non-Serializable types. |
| SupportArrayToBean | Ways to support data mapping. |
| InitStringFieldAsEmpty | Initialize the String field to the empty string, e.g: "". |
| SupportAutoType | Automatic type is supported. To read JSON data with "@type" type information, you need to open SupportAutoType explicitly. |
| SupportSmartMatch | The default is camel case exact match, after opening this, it can intelligently identify the case in camel/upper/pascal/snake/Kebab. |
| UseNativeObject | The default is to use JSONObject and JSONArray, and LinkedHashMap and ArrayList will be used after configuration. |
| SupportClassForName | To support fields of type Class, use Class.forName. This is disabled by default for security. |
| IgnoreSetNullValue | Fields with null input are ignored. |
| UseDefaultConstructorAsPossible | Use the default constructor as much as possible, and use Unsafe.allocateInstance to implement this option when fieldBase is turned on and this option is not turned on. |
| UseBigDecimalForFloats | The default configuration will use BigDecimal to parse decimals, and will use Float when turned on. |
| UseBigDecimalForDoubles | The default configuration will use BigDecimal to parse decimals, and Double will be used when turned on. |
| ErrorOnEnumNotMatch | By default, if the name of the Enum does not match, it will be ignored, and an exception will be thrown if it does not match when turned on. |
| TrimString | |
| ErrorOnNotSupportAutoType | |
| DuplicateKeyValueAsArray | |
| AllowUnQuotedFieldNames | |
# 5. JSONWriter.Feature

| JSONWriter.Feature | Description |
|-----------------------------------| --- |
| FieldBased | Field-based deserialization. If not configured, it will be serialized based on public field and getter methods by default. After configuration, it will be deserialized based on non-static fields (including private). |
| IgnoreNoneSerializable | Serialization ignores fields of non-Serializable types. |
| BeanToArray | Sequence the objects into an array format like [101,"XX"], which will be smaller. |
| WriteNulls | Serialize write null field |
| BrowserCompatible | Over a wide range of integers than JavaScript supports, the output is in string format. |
| NullAsDefaultValue | The null value is output as the default value, the null of the Number type is output as 0, the null output of the String type is "", and the output of the array and Collection type is []. |
| WriteBooleanAsNumber | Write true as 1 and false as 0. |
| WriteNonStringValueAsString | Write values of non-String types as Strings, excluding objects and data types. |
| WriteClassName | Write type information when serializing. |
| NotWriteRootClassName | When WriteClassName is turned on, the type information of the root object is not output. |
| NotWriteHashMapArrayListClassName | When WriteClassName is opened, the type information of objects of type HashMap/ArrayList is not output, and the deserialization combined with UseNativeObject can save the size of the serialized result. |
| NotWriteDefaultValue | When the value of the field is the default value, it is not output, which can save the size of the serialized result. |
| WriteEnumsUsingName | Serialize enum using name. |
| WriteEnumUsingToString |Serialize enum using toString method. |
| IgnoreErrorGetter | Error ignoring Getter methods |
| PrettyFormat | formatted json string. |
| ReferenceDetection | Turn on reference detection, which is turned off by default, which is inconsistent with fastjson 1.x. |
| WriteNameAsSymbol | Output field names as symbols, this only works under JSONB. |
| WriteBigDecimalAsPlain | Serialize BigDecimal using toPlainString, avoiding scientific notation. |
| NotWriteDefaultValue | When the value of the field is the default value, it is not output, which can save the size of the serialized result. |
| WriteEnumsUsingName | Serialize enum using name. |
| WriteEnumUsingToString |Serialize enum using toString method. |
| IgnoreErrorGetter | Error ignoring Getter methods |
| PrettyFormat | formatted json string. |
| ReferenceDetection | Turn on reference detection, which is turned off by default, which is inconsistent with fastjson 1.x. |
| WriteNameAsSymbol | Output field names as symbols, this only works under JSONB. |
| WriteBigDecimalAsPlain | Serialize BigDecimal using toPlainString, avoiding scientific notation. |


0 comments on commit 3b99622

Please sign in to comment.