3 Replies Latest reply on Dec 4, 2018 3:49 AM by Erik .

    Resteasy exports dates in textual format on wildfly 14 (Java 11) as opposed to numeric format in wildfly 9 (Java 8)

    gadeyne.bram Master

      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, Dateobjects 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]). I'm also wondering if this is a valid textual format.

      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 {
          private final ObjectMapper objectMapper;
          public JacksonConfig()
          {
              objectMapper = new ObjectMapper();
              objectMapper.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
              objectMapper.disable(SerializationFeature.WRITE_DATES_WITH_ZONE_ID);
          }
      
      
          @Override
          public ObjectMapper getContext(Class objectType)
          {
              return objectMapper;
          }
      }