Spring REST Service: how to configure to remove null objects in json response

前端 未结 10 1233
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 07:06

I have a spring webservice that returns a json response. I\'m using the example given here to create the service: http://www.mkyong.com/spring-mvc/spring-3-mvc-and-json-exam

10条回答
  •  一生所求
    2020-11-28 08:06

    I've found a solution through configuring the Spring container, but it's still not exactly what I wanted.

    I rolled back to Spring 3.0.5, removed and in it's place I changed my config file to:

        
        
            
                
                    
                
            
        
    
    
    
    
    
    
        
        
        
            
                NON_NULL
            
        
    
    

    This is of course similar to responses given in other questions e.g.

    configuring the jacksonObjectMapper not working in spring mvc 3

    The important thing to note is that mvc:annotation-driven and AnnotationMethodHandlerAdapter cannot be used in the same context.

    I'm still unable to get it working with Spring 3.1 and mvc:annotation-driven though. A solution that uses mvc:annotation-driven and all the benefits that accompany it would be far better I think. If anyone could show me how to do this, that would be great.

提交回复
热议问题