title: Custom ObjectMapper with Jersey 2.2 and Jackson 2.1
body: <p>I am struggling with a REST application with Grizzly, Jersey and Jackson, because Jersey ignores my custom ObjectMapper.</p>
  
  <p>POM dependencies:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-container-grizzly2-servlet&lt;/artifactId&gt;
          &lt;version&gt;2.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.fasterxml.jackson.jaxrs&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-jaxrs-json-provider&lt;/artifactId&gt;
          &lt;version&gt;2.1.4&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>Resulting versions are: Grizzly 2.3.3, Jackson 2.1.4 and Jersey 2.2.</p>
  
  <p>Main class (I want explicit registration of Jersey components):</p>
  
  <pre class="lang-java prettyprint-override"><code>public class Main {
      public static void main(String[] args) {
          try {
              ResourceConfig rc = new ResourceConfig();
              rc.register(ExampleResource.class);
              rc.register(ObjectMapperResolver.class);
  
              HttpHandler handler = ContainerFactory.createContainer(
                      GrizzlyHttpContainer.class, rc);
  
              URI uri = new URI("http://0.0.0.0:8080/");
  
              HttpServer server = GrizzlyHttpServerFactory.createHttpServer(uri);
  
              ServerConfiguration config = server.getServerConfiguration();
              config.addHttpHandler(handler, "/");
  
              server.start();
              System.in.read();
  
          } catch (ProcessingException | URISyntaxException | IOException e) {
              throw new Error("Unable to create HTTP server.", e);
          }
      }
  }
  </code></pre>
  
  <p>ContextResolver for ObjectMapper:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Provider
  @Produces(MediaType.APPLICATION_JSON)
  public class ObjectMapperResolver implements ContextResolver&lt;ObjectMapper&gt; {
  
      private final ObjectMapper mapper;
  
      public ObjectMapperResolver() {
          System.out.println("new ObjectMapperResolver()");
          mapper = new ObjectMapper();
          mapper.enable(SerializationFeature.INDENT_OUTPUT);
      }
  
      @Override
      public ObjectMapper getContext(Class&lt;?&gt; type) {
          System.out.println("ObjectMapperResolver.getContext(...)");
          return mapper;
      }
  
  }
  </code></pre>
  
  <p>Neither <code>ObjectMapperResolver</code> constructor nor <code>getContext</code> get called. What am I missing? I would prefer to use Jersey 2.2 and Jackson 2.1, because it is a dependency for another lib.</p>
  
  <p>A full example can be found on GitHub: <a href="https://github.com/svenwltr/example-grizzly-jersey-jackson/tree/stackoverflow">https://github.com/svenwltr/example-grizzly-jersey-jackson/tree/stackoverflow</a></p>