【7.2.5】【wrapper】更新一些类名

pull/37/head
fengshuonan 2022-09-06 16:55:57 +08:00
parent b911d7b899
commit 4ac9637014
6 changed files with 23 additions and 29 deletions

View File

@ -24,13 +24,13 @@
*/
package cn.stylefeng.roses.kernel.rule.annotation;
import cn.stylefeng.roses.kernel.rule.base.JsonFieldFormatProcess;
import cn.stylefeng.roses.kernel.rule.base.SimpleFieldFormatProcess;
import cn.stylefeng.roses.kernel.rule.enums.FormatTypeEnum;
import java.lang.annotation.*;
/**
* jsonid
* jsonidid ->
*
* @author fengshuonan
* @date 2022/9/6 11:34
@ -38,7 +38,7 @@ import java.lang.annotation.*;
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD})
public @interface JsonFieldFormat {
public @interface SimpleFieldFormat {
/**
* {@link FormatTypeEnum}
@ -50,6 +50,6 @@ public @interface JsonFieldFormat {
/**
*
*/
Class<? extends JsonFieldFormatProcess> processClass();
Class<? extends SimpleFieldFormatProcess> processClass();
}

View File

@ -6,7 +6,7 @@ package cn.stylefeng.roses.kernel.rule.base;
* @author fengshuonan
* @date 2022/9/6 11:54
*/
public interface JsonFieldFormatProcess {
public interface SimpleFieldFormatProcess {
/**
*

View File

@ -1,7 +0,0 @@
/**
*
*
* @author fengshuonan
* @date 2022/9/6 16:30
*/
package cn.stylefeng.roses.kernel.wrapper.field.impls;

View File

@ -1,13 +1,14 @@
package cn.stylefeng.roses.kernel.wrapper.field.jackson;
import cn.stylefeng.roses.kernel.rule.annotation.JsonFieldFormat;
import cn.stylefeng.roses.kernel.rule.base.JsonFieldFormatProcess;
import cn.stylefeng.roses.kernel.rule.annotation.SimpleFieldFormat;
import cn.stylefeng.roses.kernel.rule.base.SimpleFieldFormatProcess;
import cn.stylefeng.roses.kernel.rule.enums.FormatTypeEnum;
import cn.stylefeng.roses.kernel.wrapper.field.simple.SimpleFieldFormatSerializer;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
/**
* Json@JsonFieldFormat
* Json
*
* @author fengshuonan
* @date 2022/9/6 13:56
@ -21,7 +22,7 @@ public class CustomJacksonIntrospector extends JacksonAnnotationIntrospector {
@Override
public Object findSerializer(Annotated annotated) {
JsonFieldFormat formatter = annotated.getAnnotation(JsonFieldFormat.class);
SimpleFieldFormat formatter = annotated.getAnnotation(SimpleFieldFormat.class);
if (formatter == null || formatter.processClass() == null) {
return super.findSerializer(annotated);
@ -31,10 +32,10 @@ public class CustomJacksonIntrospector extends JacksonAnnotationIntrospector {
FormatTypeEnum formatTypeEnum = formatter.formatType();
// 获取具体的处理方法
Class<? extends JsonFieldFormatProcess> process = formatter.processClass();
Class<? extends SimpleFieldFormatProcess> process = formatter.processClass();
// 创建对应的序列化模式
return new CustomJsonSerializer(formatTypeEnum, process);
return new SimpleFieldFormatSerializer(formatTypeEnum, process);
}
}

View File

@ -1,6 +1,6 @@
/**
* jackson
* <p>
* jacksonjson @JsonFieldFormat {@link cn.stylefeng.roses.kernel.rule.annotation.JsonFieldFormat}
* jacksonjson @SimpleFieldFormat {@link cn.stylefeng.roses.kernel.rule.annotation.SimpleFieldFormat}
*/
package cn.stylefeng.roses.kernel.wrapper.field.jackson;

View File

@ -1,7 +1,7 @@
package cn.stylefeng.roses.kernel.wrapper.field.jackson;
package cn.stylefeng.roses.kernel.wrapper.field.simple;
import cn.hutool.core.util.ClassUtil;
import cn.stylefeng.roses.kernel.rule.base.JsonFieldFormatProcess;
import cn.stylefeng.roses.kernel.rule.base.SimpleFieldFormatProcess;
import cn.stylefeng.roses.kernel.rule.enums.FormatTypeEnum;
import cn.stylefeng.roses.kernel.wrapper.api.constants.WrapperConstants;
import com.fasterxml.jackson.core.JsonGenerator;
@ -13,13 +13,13 @@ import java.io.IOException;
import java.lang.reflect.Field;
/**
* @JsonFieldFormat
* @SimpleFieldFormat
*
* @author fengshuonan
* @date 2022/9/6 14:09
*/
@Slf4j
public class CustomJsonSerializer extends JsonSerializer<Object> {
public class SimpleFieldFormatSerializer extends JsonSerializer<Object> {
/**
* wrapper
@ -29,9 +29,9 @@ public class CustomJsonSerializer extends JsonSerializer<Object> {
/**
*
*/
private final Class<? extends JsonFieldFormatProcess> processClass;
private final Class<? extends SimpleFieldFormatProcess> processClass;
public CustomJsonSerializer(FormatTypeEnum formatTypeEnum, Class<? extends JsonFieldFormatProcess> processClass) {
public SimpleFieldFormatSerializer(FormatTypeEnum formatTypeEnum, Class<? extends SimpleFieldFormatProcess> processClass) {
this.formatTypeEnum = formatTypeEnum;
this.processClass = processClass;
}
@ -43,22 +43,22 @@ public class CustomJsonSerializer extends JsonSerializer<Object> {
String fieldName = jsonGenerator.getOutputContext().getCurrentName();
// 创建具体字段转化的实现类
JsonFieldFormatProcess jsonFieldFormatProcess = null;
SimpleFieldFormatProcess simpleFieldFormatProcess = null;
try {
jsonFieldFormatProcess = processClass.newInstance();
simpleFieldFormatProcess = processClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
log.error("执行json的字段序列化出错", e);
return;
}
// 判断当前字段值是否可以转化
boolean canFormat = jsonFieldFormatProcess.canFormat(originValue);
boolean canFormat = simpleFieldFormatProcess.canFormat(originValue);
if (!canFormat) {
return;
}
// 执行转化,获取转化过的值
Object formattedValue = jsonFieldFormatProcess.formatProcess(originValue);
Object formattedValue = simpleFieldFormatProcess.formatProcess(originValue);
try {
// 如果转化模式是替换类型