@wenshao
似乎没有启到作用:
配置代码:
public T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
T t = super.deserialze(parser, clazz, fieldName);
if (t instanceof String) {
return (T) trimAndNormalize((String) t);
} else if (t instanceof StringBuilder) {
return (T) trimAndNormalize((StringBuilder) t);
} else if (t instanceof StringBuffer) {
return (T) trimAndNormalize((StringBuffer) t);
}
return t;
}
/**
* {@inheritDoc}
*/
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
FastJsonHttpMessageConverter msgConverter = new FastJsonHttpMessageConverter();
msgConverter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON));
ParserConfig pcfg = ParserConfig.getGlobalInstance();
pcfg.putDeserializer(String.class, this);
pcfg.putDeserializer(StringBuilder.class, this);
pcfg.putDeserializer(StringBuffer.class, this);
FastJsonConfig cfg = new FastJsonConfig();
cfg.setParserConfig(pcfg);
msgConverter.setFastJsonConfig(cfg);
converters.add(msgConverter);
}
传入参数:
{
"name": "张三 ",
"phone": "李四 ",
"skill": "java ",
"recruitment": 4,
"region": "Chengdu ",
"workingYears": "3.5 "
},
仅recruitment进入了自定义的deserialze方法,当将4添加上""后,一个属性都没有进入