The JSON binding for date and calendar types must be converted

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:

@Path("/")
@ApplicationScoped
public class MyService {

@GET
@Path("/get")
@Produces(MediaType.APPLICATION_JSON)
public DataObject getData() {
//...
}

@GET
@Path("/set")
@Consumes(MediaType.APPLICATION_JSON)
public void setData(DataObject data) {
//...
}
}
import java.util.Calendar;
import java.util.Date;

public class DataObject {
public Date juDate;
public Calendar juCalendar;
}

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:

import java.util.Calendar;
import java.util.Date;
import javax.json.bind.annotation.JsonbDateFormat;

public class DataObject {
@JsonbDateFormat(value = JsonbDateFormat.TIME_IN_MILLIS)
public Date juDate;
@JsonbDateFormat(value = JsonbDateFormat.TIME_IN_MILLIS)
public Calendar juCalendar;
}

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.