The JSON binding for date, time 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]
java.time.Instant { "epochSecond":726213720, "nano":0 } 1993-02-05T06:02:00Z
java.time.LocalDate { "year":1993, "month":"FEBRUARY", "dayOfMonth":5, ... } 1993-02-05

This rule flags JAX-RS resource methods which produce or consume JSON-type data of the following types:

Methods that produce or consume any of the types listed earlier need to be converted. Note that any methods that produce or consume an object containing any of those types will also need to be addressed.

The binary scanner only detects methods that consume or produce the types mentioned earlier directly. However, if a method consumes or produces an object that contains those types, the binary scanner will not detect the type usage. If you are using the binary scanner, review all @javax.ws.rs.Produces and @javax.ws.rs.Consumes annotations that specify JSON or wildcard and ensure that any method producing or consuming objects containing any of the applicable types are converted.

The following is an example of JAX-RS resource methods which will be flagged by this rule:

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

    @GET
    @Path("/get")
    @Produces(MediaType.APPLICATION_JSON)
    public Date getDate() {
        //...
    }

    @GET
    @Path("/set")
    @Consumes(MediaType.APPLICATION_JSON)
    public void setDate(Date date) {
        //...
    }
}

For JAX-RS resource methods that directly return java.util.Date or java.util.Calendar, the return type should be changed to type long in order to maintain the same output as Jackson. For example, if a method is returning a Date object as seen here:

    @GET
    @Path("/get")
    @Produces(MediaType.APPLICATION_JSON)
    public Date getDate() {
        return new Date(...);
    }

The method can be changed to the following:

    @GET
    @Path("/get")
    @Produces(MediaType.APPLICATION_JSON)
    public long getDate() {
        return new Date(...).getTime();
    }

For the java.time.LocalDate and java.time.Instant types, it will be simpler to adjust code that consumes the date so it handles the JSON-B/Yasson format.

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.