构建包含 Long 和 LocalDateTime 定制的模块
()
| 58 | * 构建包含 Long 和 LocalDateTime 定制的模块 |
| 59 | */ |
| 60 | private SimpleModule buildCustomModule() { |
| 61 | SimpleModule simpleModule = new SimpleModule(); |
| 62 | |
| 63 | // 将所有的 long 类型序列化为 string |
| 64 | simpleModule.addSerializer(Long.class, ToStringSerializer.instance); |
| 65 | simpleModule.addSerializer(Long.TYPE, ToStringSerializer.instance); |
| 66 | |
| 67 | //序列化LocalDateTime 类型 |
| 68 | simpleModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(FORMATTER)); |
| 69 | //反序列化 LocalDateTime 类型 |
| 70 | simpleModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(FORMATTER)); |
| 71 | |
| 72 | return simpleModule; |
| 73 | } |
| 74 | |
| 75 | |
| 76 |