Reputation: 725
I have a project that works fine on Java 8 running on Wildfly 9.
I use some REST endpoints to serialize some Java objects to JSON. This is configured with Resteasy and @Produces(MediaType.APPLICATION_JSON)
.
I'm now trying to convert the project to work on wildfly 14 and Java 11.
For some reason in the previous version, Date
objects were exported as a numeric value. In the new environment, dates are exported in a textual format (e.g. 2018-12-03T10:05:33.39Z[UTC]
).
The strange thing is that some data properties of some objects are still exported in the numeric format and others are exported in the textual format.
I've tried enabling the WRITE_DATES_AS_TIMESTAMPS
feature but this doesn't change the result.
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
@Provider
@Produces(MediaType.APPLICATION_JSON)
public class JacksonConfig implements ContextResolver<ObjectMapper> {
private final ObjectMapper objectMapper;
public JacksonConfig()
{
objectMapper = new ObjectMapper();
objectMapper.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}
@Override
public ObjectMapper getContext(Class<?> objectType)
{
return objectMapper;
}
}
Upvotes: 2
Views: 875
Reputation: 725
The issue was related to the switch from jackson to jsonb.
It is further explained in this thread.
Upvotes: 1