Ext JS – Serialize Date using Jackson and Spring 3

From bottom to top:

  1. In the database (MS SQLServer): column is a datetime (aka, a timestamp)
  2. 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; }
    
  3. Configured Jackson object mapper to use ISO-8601 format
    objectMapper.configure(SerializationConfig.WRITE_DATES_AS_TIMESTAMPS, false);
    
  4. 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'}
    	]
    });
    
  5. 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

Advertisements

2 comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s