javaspringwildflyjava-11wildfly-15

Date serialization issue while upgrading from Wildfly 11 to Wildfly 15


We have recently migrated from Wildfly 11 to Wildfly 15 and from Java 8 to Java 11 and noticed a change in how Jackson serializes Date objects. We use Jackson v2.9.8 for object serialization and Spring v5.0.9.

Prior to our upgrade, a date object would be serialized in an ISO format e.g. "2019-11-12" but after the upgrade, the date fields started to appear as Timestamps e.g. "1573516800000'. Has anyone else faced this issue before? Is this something that can be configured in standalone.xml?

Wildfly 11 Example

pre-upgrade date serialization

Wildfly 15 Example

post-upgrade date serialization

The field is configured as DATE in MySQL

enter image description here

Example Entity

public class Entity implements java.io.Serializable {

  @Id
  @Column(name = "id")
  private Integer id;

  @Column(name = "value_date")
  private java.sql.Date valueDate;

  public java.sql.Date getValueDate() {
    return valueDate;
  }

  public void setValueDate(java.sql.Date valueDate) {
    this.valueDate = valueDate;
  }
}

EDIT:


Solution

  • Although I cannot be sure about your current setup/config, if you configure your ObjectMapper, you will probably get the expected behavior:

    @Bean
    @Primary
    public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
        ObjectMapper objectMapper = builder.build();
        objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
        return objectMapper;
    }