spring4解决json返回null值为“null”字符串问题

pom.xml

 


            com.fasterxml.jackson.core
            jackson-core
            2.0.4
        
        
            com.fasterxml.jackson.core
            jackson-databind
            2.0.4
        
 

 

代码:

 

public class CustomerObjectMapper extends ObjectMapper {
 
    {
        DefaultSerializerProvider.Impl sp = new DefaultSerializerProvider.Impl();
        sp.setNullValueSerializer(new NullSerializer());
        this.setSerializerProvider(sp);
    }
 
    public class NullSerializer extends JsonSerializer {
        public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException,
                JsonProcessingException {
 
            jgen.writeString("");
        }
    }
 
}   
   

 

 

 

spring配置:


    
    
    
    
    
    
    
 
    

 

你可能感兴趣的:(spring,json,java)