Java Spring Jackons Date serialization

后端 未结 4 1131
野的像风
野的像风 2021-01-13 00:20

I\'m using Spring MVC and Jackson for JSON de/serialization. But im facing a problem with serializing a date.

By default Jackson serialize a date as an epoch. But i

4条回答
  •  迷失自我
    2021-01-13 00:44

    Much simpler way to do this now in Spring 3.1.

    public class CustomObjectMapper extends ObjectMapper {
    
        public CustomObjectMapper() {
            configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);            
            setDateFormat(new ISO8601DateFormat());
        }
    }
    

    And then register this as a bean and customize the mvc:annotation-driven element.

    
        
            
                    
            
        
    
    
    
    

提交回复
热议问题