Java – where can I specify Jackson serializationconfig. In spring 3.1 Feature settings
I'm confused about why the default Jackson is included. Spring seems to have customized the default Jackson configuration
One setting that is confusing is write_ DATES_ AS_ Timestamp, Jackson default is true, but spring changed it to false somewhere and also provided date format
Where is the world? I want my date to remain serialized as a number
Update: it turns out that this is not the spring that caused the problem. It is actually the dormant agent class that caused the problem For some reason, if hibernate has a type mapping with type = "date", it will be serialized as a date string, but if its type is "timestamp", it will be arranged in the expected order Instead of spending too much time on this issue, I decided to change all mappings to timestamp now
Solution
Starting with 3.1 M1, you can specify Jackson's custom configuration by registering an httpmessageconverter and using the child element of MVC: annotation driven
See spring 3.1 MVC namespace improvements
See spr-7504 to make it easier to add a new message converter to the annotation method handler adapter
Example:
<bean id="jacksonObjectMapper" class="x.y.z.CustomObjectMapper"> </bean> <mvc:annotation-driven> <mvc:message-converters> <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> <property name="objectMapper" ref="jacksonObjectMapper" /> </bean> </mvc:message-converters> </mvc:annotation-driven>
Customobjectmapper object
@Component("jacksonObjectMapper") public class CustomObjectMapper extends ObjectMapper { @postconstruct public void afterPropertiesSet() throws Exception { SerializationConfig serialConfig = getSerializationConfig() .withDateFormat(null); //any other configuration this.setSerializationConfig(serialConfig); } }