Ext JS – Serialize Date using Jackson and Spring 3
From bottom to top:
- In the database (MS SQLServer): column is a datetime (aka, a timestamp)
- In domain object, need the @Temporal(TemporalType.TIMESTAMP) annotation (using Hibernate 3x). Note, I also added @JsonProperty for Jackson b/c I wanted a shorter name in the JSON.
@Temporal(TemporalType.TIMESTAMP) @Column(name="REGISTRATION_DATE") private Date registrationDate; @JsonProperty("regDate") public Date getRegistrationDate() { return registrationDate; } public void setRegistrationDate(Date registrationDate) { this.registrationDate = registrationDate; } - Configured Jackson object mapper to use ISO-8601 format
objectMapper.configure(SerializationConfig.WRITE_DATES_AS_TIMESTAMPS, false);
- Define field in Ext JS 4 model as a Date type, using the ‘c’ date format.
Ext.define('User', { extend: 'Ext.data.Model', fields: [ {name: 'regDate', type: 'date', dateFormat: 'c'} ] }); - Show the date in a user friendly format in the grid. Ext JS 4, column config:
{text: 'Registration Date', dataIndex: 'regDate', sortable: true, xtype: 'datecolumn', format:'m-d-Y'}
Helpful Links