In JAX-RS 2.1, the internal library used for serialization and deserialization between JSON and Java objects has changed from Jackson to Yasson. Yasson is the reference implementation of JSON-B. Jackson and Yasson will serialize time-related objects in different ways, for example:
| Jackson | Yasson | |
|---|---|---|
| java.util.Date | 726213720000 | 1993-02-05T06:02:00Z[UTC] |
| java.util.Calendar | 726213720000 | 1993-02-05T00:00:00-06:00[America/Chicago] |
Any JAX-RS resource methods which produce or consume JSON-type data may be effected. This rule flags any java.util.Date or java.util.Calendar fields that are contained in an object produced or consumed by a JAX-RS
resource method.
The following is an example of JAX-RS resource methods which produce and consume a Java Object containing a java.util.Date and java.util.Calendar field:
This rule flags the java.util.Date and java.util.Calendar fields in the DataObject object.
For this rule, an automated fix will be provided to add the annotation @JsonbDateFormat(value = JsonbDateFormat.TIME_IN_MILLIS)
to these fields to convert the output to epoch milliseconds.After the automated fix is applied the DataObject class
will be updated as follows:
Note: In order to access the @javax.json.bind.annotation.JsonbDateFormat
annotation will be added by the automated fix, The automated fix will add the jsonb feature to your Liberty
server.xml configuration file. For example, add the jsonb-1.0 feature if you are using the
jaxrs-2.1 feature.
For more details about behavior differences between Jackson and Yasson, see the Is it time for a JSON binding standard? article comparing Jackson and JSON-B behavior.