springmvc配置文件
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>text/html;charset=UTF-8</value> <value>application/json;charset=UTF-8</value> </list> </property> <property name="objectMapper"> <bean class="com.fasterxml.jackson.databind.ObjectMapper"> <property name="serializerProvider"> <bean class="com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.Impl"> <property name="nullValueSerializer"> <bean class="com.xxx.xxx.NullValueSerializer"></bean> </property> </bean> </property> </bean> </property> </bean>
NullValueSerializer
public class NullValueSerializer extends JsonSerializer<Object> { @Override public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeString(""); } }