8.0 Godfather Changes

Date Type change

Description of the Backend Change

In 8.0 Godfather release, there was a low-level change regarding the datetime (timestamp) fields representation in the core code, domain objects. While it was a big low-level change, it has kept the backward compatibility. To sum up the change, in the server Java code Pricefx now uses LocalDateTime (more modern representation of datetime values in Java JDK) instead of the traditional java.util.Date.

We invested a major effort to minimize possible impacts. So for example, all JSON serialization/deserialization should be backward compatible, as well as processing the domain objects in the Groovy logics (that means that even if the LocalDateTime is stored internally in the Pricefx core server code, the existing logics still get the values represented as java.util.Date to stay compatible with older Pricefx versions).

Reasons/Motivation

The reasons were related to performance. This change was based on the recommendation from the Hibernate project team with the goal to improve performance / lower CPU utilization.

Impact on Logics

There can be some corner cases. For example, when the Groovy logic relies on the default behavior of conversion of Date to string using the toString() method - i.e. without some formatter (e.g. SimpleDateFormat) and when this string representation is later parsed into object again.

For example, if some of the table fields were originally returned as java.sql.Timestamp (that is subclass of java.util.Date), and now they return differently, then the behavior of their toString() methods differs.

In Godfather, both are internally replaced with LocalDateTime, but for the backward compatibility, they are converted into java.util.Date in the logic. So there could be a change in the default toString() behavior.

How to Avoid Potential Issues

  • If possible, do not convert values of the Date type to string and back just to get the original value.

  • Use a formatter - such as SimpleDateFormat - to control what specific format is used for formatting to String or when parsing from String.

    Implementation of toString() in the JDK classes is outside of Pricefx control, so when the default formatting is different in java.sql.Timestamp and java.util.Date, it can lead to different results.

  • Check the data type of the field with date - e.g. using instanceof.

Samples of conversion of date to a string in a controlled way in a logic Groovy code:
api.targetDate().format("yyyy-mm-dd hh:mm:ss") //❶ new SimpleDateFormat("yyyy-mm-dd hh:mm:ss").format(api.targetDate())

❶ this is using the Date.format() method from Groovy JDK enhancements

Found an issue in documentation? Write to us.