### 1. 启用 `@GoEnableFastJson` ### 2. 配置yml文件 ``` fastjson: date-format: yyyy-MM-dd HH:mm:ss desensitize: true ``` date-format:日期格式,默认yyyy-MM-dd HH:mm:ss desensitize:启用脱敏,默认true启用 ### 3. 注意事项 本框架中默认配置干了3件事情,后续版本更佳灵活自定义配置 * 1、序列化属性 | 配置 | 描述 | | --- | --- | | WriteNullStringAsEmpty | 字符类型如果为null,输出为"" | | WriteNullNumberAsZero | 数值类型如果为null,输出为0 | | WriteNullBooleanAsFalse | 真假类型如果为null,输出为false | | WriteEnumUsingToString | 枚举类型,使用ToString作为输出 | | WriteDateUseDateFormat | 日期类型,使用格式化后输出 | | IgnoreErrorGetter | 忽略错误的get | | DisableCircularReferenceDetect | 禁用循环引用 | 更多属性 ![](https://img.kancloud.cn/8e/e1/8ee1aa0162089306631c71b78a561001_691x957.png) * 2、自定义过滤器 | 过滤 | 描述 | | --- | --- | | DesensitizeFilter | 脱敏信息(名字、身份证、座机号、手机号、地址、邮箱、银行卡、密码,车牌号| * 3、序列化配置 | 类型 | 描述 | | --- | --- | | Date | 格式化日期 | | Long、BigInteger、BigDecimal | 防止丢失精度 | ### 3. 测试示例 TestDto.java ``` @Data public class TestDto { // ==== @GoDesensitized(type = SensitiveTypeEnum.CHINESE_NAME) @JSONField(ordinal = 1) private String realname; @JSONField(ordinal = 2) private String nickname; @JSONField(ordinal = 3) private Integer age; @JSONField(ordinal = 4) @GoDesensitized(type = SensitiveTypeEnum.MOBILE) private String tel; @JSONField(ordinal = 5) private Boolean vip; @JSONField(ordinal = 6) private Date birthDay; @JSONField(ordinal = 7) private StatusEnum status; @JSONField(ordinal = 8) private BigDecimal balance; // ==== @JSONField(ordinal = 9, format = "$#0.00") public BigDecimal getBalanceFormat() { return this.balance; } // ==== public static enum StatusEnum { A(0, "管理"), B(1, "机构"), C(2, "会员"); public final int index; public final String status; StatusEnum(int i, String status) { this.index = i; this.status = status; } public int getIndex() { return index; } public String getStatus() { return status; } @Override public String toString() { return this.getStatus(); } } } ``` ``` @RequestMapping("/test") public TestDto test() { TestDto dto = new TestDto(); dto.setRealname("张三"); // dto.setNickname(nickname); // dto.setAge(age); dto.setTel("13800138000"); // dto.setVip(vip); dto.setBirthDay(new Date()); dto.setStatus(StatusEnum.A); dto.setBalance(new BigDecimal(123.12)); return dto; } ``` ### 4. 验证结果 ``` { "code": 0, "msg": "操作成功", "data": { "realname": "张*", "nickname": "", "age": 0, "tel": "138****8000", "vip": false, "birthDay": "2020-08-31 18:19:24", "status": "管理", "balance": 123.12, "balanceFormat": "$123.12" }, "success": true } ```