|
@@ -2,6 +2,12 @@ package com.chelvc.framework.base.jackson;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
+import com.chelvc.framework.base.annotation.Enumerate;
|
|
|
+import com.chelvc.framework.base.context.ApplicationContextHolder;
|
|
|
+import com.chelvc.framework.base.context.SessionContextHolder;
|
|
|
+import com.chelvc.framework.common.model.Enumeration;
|
|
|
+import com.chelvc.framework.common.util.ObjectUtils;
|
|
|
+import com.chelvc.framework.common.util.StringUtils;
|
|
|
import com.fasterxml.jackson.core.JsonGenerator;
|
|
|
import com.fasterxml.jackson.databind.BeanProperty;
|
|
|
import com.fasterxml.jackson.databind.JsonSerializer;
|
|
@@ -9,12 +15,6 @@ import com.fasterxml.jackson.databind.SerializerProvider;
|
|
|
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
|
|
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
-import com.chelvc.framework.base.annotation.Enumerate;
|
|
|
-import com.chelvc.framework.base.context.ApplicationContextHolder;
|
|
|
-import com.chelvc.framework.base.context.SessionContextHolder;
|
|
|
-import com.chelvc.framework.common.model.Enumeration;
|
|
|
-import com.chelvc.framework.common.util.ObjectUtils;
|
|
|
-import com.chelvc.framework.common.util.StringUtils;
|
|
|
|
|
|
/**
|
|
|
* Jackson枚举对象结构化处理器
|
|
@@ -23,12 +23,11 @@ import com.chelvc.framework.common.util.StringUtils;
|
|
|
* @date 2023/1/1
|
|
|
*/
|
|
|
public class EnumerationFormatSerializer extends StdSerializer<Object> implements ContextualSerializer {
|
|
|
- private boolean enabled;
|
|
|
private Enumerate annotation;
|
|
|
+ private boolean enabled = true;
|
|
|
|
|
|
public EnumerationFormatSerializer() {
|
|
|
super(Object.class);
|
|
|
- this.enabled = true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -123,7 +122,7 @@ public class EnumerationFormatSerializer extends StdSerializer<Object> implement
|
|
|
@Override
|
|
|
public void serialize(Object object, JsonGenerator generator, SerializerProvider provider)
|
|
|
throws IOException {
|
|
|
- if (!this.enabled || this.annotation == null || object == null) {
|
|
|
+ if (!this.enabled || object == null) {
|
|
|
generator.writeObject(object);
|
|
|
} else {
|
|
|
generator.writeObject(ImmutableMap.of(
|
|
@@ -141,7 +140,7 @@ public class EnumerationFormatSerializer extends StdSerializer<Object> implement
|
|
|
this.enabled = false;
|
|
|
} else {
|
|
|
this.annotation = this.getEnumerateAnnotation(property);
|
|
|
- this.enabled = this.annotation != null && this.isVersioning(this.annotation);
|
|
|
+ this.enabled = this.annotation == null || this.isVersioning(this.annotation);
|
|
|
}
|
|
|
return this;
|
|
|
}
|