5 Replies Latest reply on May 24, 2019 9:42 AM by surfspider

    WildFly 15: Deserialize / serialize LocalDateTime as number

    Gerrit Hohl Newbie

      Hello everyone,


      in the following thread there is a discussion how to enable the behaviour, that JSON-B returns e.g. LocalDateTime as a timestamp in milliseconds:

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

      That works fine - with one downside: Before such values were returned as numbers, but now they are returned as strings.


      Is there any possibility to configure the JSON-B in a way that it returns such objects as numbers?


      My code:

      import javax.json.bind.Jsonb;
      import javax.json.bind.JsonbBuilder;
      import javax.json.bind.JsonbConfig;
      import javax.json.bind.annotation.JsonbDateFormat;
      import javax.ws.rs.Produces;
      import javax.ws.rs.core.MediaType;
      import javax.ws.rs.ext.ContextResolver;
      import javax.ws.rs.ext.Provider;
      import org.jboss.logging.Logger;
      public class JsonbContextResolver implements ContextResolver {
          /** The logging. */
          private static Logger log = Logger.getLogger(JsonbContextResolver.class);
          private Jsonb         jsonB;
          public JsonbContextResolver() {
          private void initialize() {
              JsonbConfig config;
              log.info("Created " + this.getClass().getSimpleName());
              config = new JsonbConfig();
              config.setProperty(JsonbConfig.DATE_FORMAT, JsonbDateFormat.TIME_IN_MILLIS);
              this.jsonB = JsonbBuilder.create(config);
          public Jsonb getContext(Class type) {
              log.info("Retrieved object class: " + type.toGenericString());
              return this.jsonB;