update
This commit is contained in:
@@ -83,9 +83,50 @@ public class JsonMapper extends ObjectMapper {
|
|||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static final String[] pattern = new String[] {"yyyy", "MM", "dd", "HH", "mm", "ss", "SSS"};
|
private static final String[] pattern = new String[] {"yyyy", "MM", "dd", "HH", "mm", "ss", "SSS"};
|
||||||
private static class JeeSiteJsonSerializer extends JsonSerializer<Date> {
|
@Override
|
||||||
|
public Object findSerializer(Annotated a) {
|
||||||
|
if (a instanceof AnnotatedMethod) {
|
||||||
|
AnnotatedMethod am = (AnnotatedMethod) a;
|
||||||
|
if (am.getRawReturnType() == Date.class) {
|
||||||
|
JsonFormat jf = am.getAnnotation(JsonFormat.class);
|
||||||
|
if (jf != null && StringUtils.containsAnyIgnoreCase(jf.pattern(), pattern)) {
|
||||||
|
return new JeeSiteJsonSerializer(jf.pattern());
|
||||||
|
}
|
||||||
|
return new JeeSiteJsonSerializer(null);
|
||||||
|
}
|
||||||
|
} else if (a instanceof AnnotatedClass) {
|
||||||
|
if (a.getRawType() == Date.class) {
|
||||||
|
return new JeeSiteJsonSerializer(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.findSerializer(a);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Object findDeserializer(Annotated a) {
|
||||||
|
if (a instanceof AnnotatedMethod) {
|
||||||
|
AnnotatedMethod am = (AnnotatedMethod) a;
|
||||||
|
if (am.getParameterCount() > 0 && am.getParameterType(0).getRawClass() == Date.class) {
|
||||||
|
AnnotatedElement m = am.getAnnotated();
|
||||||
|
JsonFormat jf = m.getAnnotation(JsonFormat.class);
|
||||||
|
if (jf != null && StringUtils.containsAnyIgnoreCase(jf.pattern(), pattern)) {
|
||||||
|
return new JeeSiteJsonDeserializer(jf.pattern());
|
||||||
|
}
|
||||||
|
return new JeeSiteJsonDeserializer(null);
|
||||||
|
}
|
||||||
|
} else if (a instanceof AnnotatedClass) {
|
||||||
|
if (a.getRawType() == Date.class) {
|
||||||
|
return new JeeSiteJsonDeserializer(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.findDeserializer(a);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final class JeeSiteJsonSerializer extends JsonSerializer<Date> {
|
||||||
private final String pattern;
|
private final String pattern;
|
||||||
private JeeSiteJsonSerializer(String pattern) {
|
public JeeSiteJsonSerializer(String pattern) {
|
||||||
this.pattern = pattern;
|
this.pattern = pattern;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
@@ -99,9 +140,10 @@ public class JsonMapper extends ObjectMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static class JeeSiteJsonDeserializer extends JsonDeserializer<Date> {
|
|
||||||
|
public static final class JeeSiteJsonDeserializer extends JsonDeserializer<Date> {
|
||||||
private final String pattern;
|
private final String pattern;
|
||||||
private JeeSiteJsonDeserializer(String pattern) {
|
public JeeSiteJsonDeserializer(String pattern) {
|
||||||
this.pattern = pattern;
|
this.pattern = pattern;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
@@ -113,47 +155,6 @@ public class JsonMapper extends ObjectMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override
|
|
||||||
public Object findSerializer(Annotated a) {
|
|
||||||
if (a instanceof AnnotatedMethod) {
|
|
||||||
AnnotatedElement m = a.getAnnotated();
|
|
||||||
JsonFormat jf = m.getAnnotation(JsonFormat.class);
|
|
||||||
if (jf != null && StringUtils.containsAnyIgnoreCase(jf.pattern(), pattern)) {
|
|
||||||
return new JeeSiteJsonSerializer(jf.pattern());
|
|
||||||
}
|
|
||||||
AnnotatedMethod am = (AnnotatedMethod) a;
|
|
||||||
if (am.getRawReturnType() == Date.class) {
|
|
||||||
return new JeeSiteJsonSerializer(null);
|
|
||||||
}
|
|
||||||
} else if (a instanceof AnnotatedClass) {
|
|
||||||
if (a.getRawType() == Date.class) {
|
|
||||||
return new JeeSiteJsonSerializer(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return super.findSerializer(a);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public Object findDeserializer(Annotated a) {
|
|
||||||
if (a instanceof AnnotatedMethod) {
|
|
||||||
AnnotatedElement m = a.getAnnotated();
|
|
||||||
JsonFormat jf = m.getAnnotation(JsonFormat.class);
|
|
||||||
if (jf != null && StringUtils.containsAnyIgnoreCase(jf.pattern(), pattern)) {
|
|
||||||
return new JeeSiteJsonDeserializer(jf.pattern());
|
|
||||||
}
|
|
||||||
AnnotatedMethod am = (AnnotatedMethod) a;
|
|
||||||
if (am.getParameterCount() > 0 && am.getParameterType(0).getRawClass() == Date.class) {
|
|
||||||
return new JeeSiteJsonDeserializer(null);
|
|
||||||
}
|
|
||||||
} else if (a instanceof AnnotatedClass) {
|
|
||||||
if (a.getRawType() == Date.class) {
|
|
||||||
return new JeeSiteJsonDeserializer(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return super.findDeserializer(a);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开启将空值转换为空字符串
|
* 开启将空值转换为空字符串
|
||||||
|
|||||||
Reference in New Issue
Block a user