1

I have a REST web-service created in Java. I am using Joda-time for the date and Jackson for the JSON formatting. Everything is uploaded on a Glassfish 4.1 server

Versions

  • avax.ws.rs-api-2.0.1.jar
  • joda-time-2.7.jar
  • jackson-annotation-2.8.8.jar
  • jackson-core-2.8.8.jar
  • jackson-databind-2.8.8.jar
  • jackson.datatype-joda-2.8.8.jar

Mapper

@Provider
public class ObjectMapperContextResolver implements ContextResolver<ObjectMapper>{

    final ObjectMapper mapper = new ObjectMapper();

    public ObjectMapperContextResolver() {
        mapper.registerModule(new JodaModule());
    }

    @Override
    public ObjectMapper getContext(Class<?> type) {
        return mapper;
    }  
}

Error when calling the service

java.lang.NoSuchFieldError: WRITE_DURATIONS_AS_TIMESTAMPS

What I found

I already found that it may have a mismatch between different versions. All the jars come from maven repository and I took each times the dependencies needed.

Question

What am I missing ? Is there a missing library ? Is there a wrong library's version ?

Note: I am not using Maven

Update

I tried to update the jackson-?.jars inside glassfish4.1/glassfish/modules but now I cant even start the server because of a requirement mismatch with jackson versions

Updates 2

Is there a way to use the jackson libraries that are inside my project instead of the one in Glassfish ? This seems to be the solution

Weedoze
  • 13,683
  • 1
  • 33
  • 63

1 Answers1

1

Is there a way to use the Jackson libraries that are inside my project instead of the one in Glassfish? This seems to be the solution.

See the following quote from the chapter 2 of the GlassFish 4 Application Development Guide:

The Java Servlet specification recommends that a web module's class loader look in the local class loader before delegating to its parent. You can make this class loader follow the delegation inversion model in the Servlet specification by setting delegate="false" in the class-loader element of the glassfish-web.xml file. It is safe to do this only for a web module that does not interact with any other modules. [...]

The default value is delegate="true", which causes a web module's class loader to delegate in the same manner as the other class loaders. You must use delegate="true" for a web application that accesses EJB components or that acts as a web service client or endpoint. [...]

For a number of packages, including java.* and javax.*, symbol resolution is always delegated to the parent class loader regardless of the delegate setting. This prevents applications from overriding core Java runtime classes or changing the API versions of specifications that are part of the Java EE platform.

In the section B of the GlassFish 4 Application Deployment Guide you'll find an example of the glassfish-web.xml deployment descriptor. Tailoring it to your issue, your glassfish-web.xml file would be like:

<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD
GlassFish Application Server 3.1 Servlet 3.0//EN"
"http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
    <class-loader delegate="false" />
</glassfish-web-app>

Then place it under WEB-INF of your web module.

cassiomolin
  • 124,154
  • 35
  • 280
  • 359
  • 1
    I am now blocked with another problem linked to Joda but I think that your solution fixed my first error. Thanks ! – Weedoze Jun 20 '17 at 09:02
  • @Weedoze If you ask another question, the Stack Overflow community may be able to help you :) – cassiomolin Jun 20 '17 at 09:05
  • 1
    I know I know hehe I will first try to find a solution myself. Thanks for your help ! – Weedoze Jun 20 '17 at 09:08
  • I finally asked [another question](https://stackoverflow.com/questions/44652189/deserialize-datetime-joda-with-jackson) – Weedoze Jun 20 '17 at 11:53