0

I have a system I'm building on Wildfly 10.1. I'd like to move to the Java 8 time API, but I'm having trouble. I've settled on OffsetDateTime to replace Calendar. At the moment, Wildfly is serializing these as

{
  "offset":
  {
    "totalSeconds":-25200,
    "id":"-07:00",
    "rules":
    {
      "fixedOffset":true,
      "transitions":[],
      "transitionRules";[]
    }
  },
  "month":"FEBRUARY",
  "year":2011,
  "hour":0,
  "minute":0,
  "second":0,
  "dayOfMonth":22,
  "dayOfWeek":"TUESDAY",
  "dayOfYear":53,
  "monthValue":2,
  "nano":0
}

which is apparently not correct. Based on this StackOverflow question I added the following class:

import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Provider;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

@Provider
public class JSR310ContextResolver
        implements ContextResolver<ObjectMapper>
{
    private final ObjectMapper MAPPER;

    public JSR310ContextResolver()
    {
        super();

        MAPPER = new ObjectMapper();
        MAPPER.registerModule(new JavaTimeModule());
        //MAPPER.registerModule(new Jdk8Module());
        MAPPER.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    }

    @Override
    public ObjectMapper getContext(Class<?> arg0)
    {
        return MAPPER;
    }
}

I'm now getting a ClassNotFoundException on JavaTimeModule. I'm not using Maven, and I have verified that jackson-datatype-jsr310.jar is present, it is under \modules\system\layers\base\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\main. My application is packaged as an EAR.

How do I configure Wildfly 10.1 to give my application access to this JAR file?

Community
  • 1
  • 1

1 Answers1

0

I found one answer: Add

    <global-modules>
        <module name="com.fasterxml.jackson.datatype.jackson-datatype-jsr310" slot="main"/>
    </global-modules>

to the

<subsystem xmlns="urn:jboss:domain:ee:4.0">

section of the configuration file.

Is anyone aware of a method to do this non-globally?