Sprintboot默认是通过jackson来转换JSON的,@JSONField(serialize = false)
是FastJson的注解,Springboot使用jackson进行转JSON的时候并不会扫描这个注解。
@Bean public HttpMessageConverters fastJsonHttpMessageConverters() { FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter(); FastJsonConfig fastJsonConfig = new FastJsonConfig(); fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat); fastConverter.setFastJsonConfig(fastJsonConfig); HttpMessageConverter<?> converter = fastConverter; return new HttpMessageConverters(converter); }
@JSONField(serialize = false)
private transient String brandJson;
就可以正常使用了