|
@@ -6,18 +6,12 @@ import java.lang.reflect.Type;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
|
|
-import org.apache.commons.io.IOUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.http.HttpInputMessage;
|
|
import org.springframework.http.HttpInputMessage;
|
|
import org.springframework.http.HttpOutputMessage;
|
|
import org.springframework.http.HttpOutputMessage;
|
|
import org.springframework.http.converter.HttpMessageNotReadableException;
|
|
import org.springframework.http.converter.HttpMessageNotReadableException;
|
|
import org.springframework.http.converter.HttpMessageNotWritableException;
|
|
import org.springframework.http.converter.HttpMessageNotWritableException;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
|
-import com.alibaba.fastjson.parser.DefaultJSONParser;
|
|
|
|
-import com.alibaba.fastjson.parser.JSONToken;
|
|
|
|
-import com.alibaba.fastjson.parser.ParserConfig;
|
|
|
|
-import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
|
|
|
|
import com.alibaba.fastjson.serializer.JSONSerializer;
|
|
import com.alibaba.fastjson.serializer.JSONSerializer;
|
|
import com.alibaba.fastjson.serializer.ObjectSerializer;
|
|
import com.alibaba.fastjson.serializer.ObjectSerializer;
|
|
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
|
|
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
|
|
@@ -33,12 +27,7 @@ public class LocalFastJsonHttpMessageConverter extends FastJsonHttpMessageConver
|
|
|
|
|
|
@Override
|
|
@Override
|
|
protected Object readInternal(Class<? extends Object> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
|
|
protected Object readInternal(Class<? extends Object> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
|
|
- return read(clazz, null, inputMessage);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public Object read(Type type, Class<?> contextClass, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
|
|
|
|
- return JSON.parseObject(IOUtils.toString(inputMessage.getBody()), type, CustmerParserConfig.global, getFastJsonConfig().getFeatures());
|
|
|
|
|
|
+ return super.readInternal(clazz, inputMessage);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -46,49 +35,20 @@ public class LocalFastJsonHttpMessageConverter extends FastJsonHttpMessageConver
|
|
|
|
|
|
OutputStream out = outputMessage.getBody();
|
|
OutputStream out = outputMessage.getBody();
|
|
JsonUtil.getConfig().put(Date.class, new SimpleDateFormatSerializer(FORMAT));
|
|
JsonUtil.getConfig().put(Date.class, new SimpleDateFormatSerializer(FORMAT));
|
|
- // JsonUtil.getConfig().put(String.class, new EmojiSerializer());
|
|
|
|
- String text = JsonUtil.toJSONString(obj, EnumFilter.instance, getFastJsonConfig().getSerializerFeatures());
|
|
|
|
- byte[] bytes = text.getBytes(getFastJsonConfig().getCharset());
|
|
|
|
|
|
+ //JsonUtil.getConfig().put(String.class, new EmojiSerializer());
|
|
|
|
+ String text = JsonUtil.toJSONString(obj, EnumFilter.instance, getFeatures());
|
|
|
|
+ byte[] bytes = text.getBytes(getCharset());
|
|
out.write(bytes);
|
|
out.write(bytes);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-class EmojiSerializer implements ObjectSerializer {
|
|
|
|
|
|
+class EmojiSerializer implements ObjectSerializer{
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
|
|
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
|
|
serializer.write(EmojiParser.parseToUnicode(object.toString()));
|
|
serializer.write(EmojiParser.parseToUnicode(object.toString()));
|
|
}
|
|
}
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-class CustmerEnumDeserializer implements ObjectDeserializer {
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public BaseEnum deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
|
|
|
|
- Object value = parser.parse();
|
|
|
|
- Class clazz = (Class) type;
|
|
|
|
-
|
|
|
|
- for (Object en : clazz.getEnumConstants()) {
|
|
|
|
- BaseEnum be = (BaseEnum) en;
|
|
|
|
- if (be.getCode() instanceof Integer) {
|
|
|
|
- if ((Integer) be.getCode() == Integer.parseInt(value.toString())) {
|
|
|
|
- return be;
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- if (value.equals(String.valueOf(be.getCode()))) {
|
|
|
|
- return be;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public int getFastMatchToken() {
|
|
|
|
- return JSONToken.LITERAL_INT;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
class EnumFilter implements ValueFilter {
|
|
class EnumFilter implements ValueFilter {
|
|
@@ -112,21 +72,3 @@ class EnumFilter implements ValueFilter {
|
|
return value;
|
|
return value;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-class CustmerParserConfig extends ParserConfig {
|
|
|
|
-
|
|
|
|
- public static CustmerParserConfig global = new CustmerParserConfig();
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public ObjectDeserializer getDeserializer(Class<?> clazz, Type type) {
|
|
|
|
- ObjectDeserializer derializer = getDeserializers().get(type);
|
|
|
|
- if (derializer != null) {
|
|
|
|
- return derializer;
|
|
|
|
- }
|
|
|
|
- if (BaseEnum.class.isAssignableFrom(clazz)) {
|
|
|
|
- putDeserializer(type, new CustmerEnumDeserializer());
|
|
|
|
- }
|
|
|
|
- return super.getDeserializer(clazz, type);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|