【7.2.5】【wrapper】更新序列化策略

pull/37/head
fengshuonan 2022-09-06 18:04:22 +08:00
parent 902ae21c22
commit ffd149e4dc
3 changed files with 8 additions and 6 deletions

View File

@ -56,9 +56,7 @@ public class EnumFieldFormatSerializer extends JsonSerializer<Object> {
}
// 进行数据转化写入到渲染的JSON中
if (!originValue.equals(formattedValue)) {
CommonFormatUtil.writeField(formatTypeEnum, originValue, formattedValue, jsonGenerator);
}
CommonFormatUtil.writeField(formatTypeEnum, originValue, formattedValue, jsonGenerator);
}

View File

@ -54,9 +54,7 @@ public class SimpleFieldFormatSerializer extends JsonSerializer<Object> {
Object formattedValue = simpleFieldFormatProcess.formatProcess(originValue);
// 将转化的值根据策略进行写入到渲染的json中
if (!originValue.equals(formattedValue)) {
CommonFormatUtil.writeField(formatTypeEnum, originValue, formattedValue, jsonGenerator);
}
CommonFormatUtil.writeField(formatTypeEnum, originValue, formattedValue, jsonGenerator);
}

View File

@ -30,6 +30,12 @@ public class CommonFormatUtil {
*/
public static void writeField(FormatTypeEnum formatTypeEnum, Object originValue, Object formattedValue, JsonGenerator jsonGenerator) {
try {
// 如果原始值和转化值一样,则直接返回
if (originValue.equals(formattedValue)) {
jsonGenerator.writeObject(originValue);
return;
}
// 如果转化模式是替换类型
if (formatTypeEnum.equals(FormatTypeEnum.REPLACE)) {
jsonGenerator.writeObject(formattedValue);