title: force glassfish 4 to use jackson 2.3
body: <p>I wrote an maven application which should run on Glassfish 4.</p>
  
  <p>The Standard ApplicationConfig looks like this:</p>
  
  <pre><code>@javax.ws.rs.ApplicationPath("resources")
  public class ApplicationConfig extends Application {
  
      @Override
      public Set&lt;Class&lt;?&gt;&gt; getClasses() {
          Set&lt;Class&lt;?&gt;&gt; resources = new java.util.HashSet&lt;Class&lt;?&gt;&gt;();
          // following code can be used to customize Jersey 2.0 JSON provider:
  
          try {
             Class jsonProvider = Class.forName("org.glassfish.jersey.jackson.JacksonFeature");
  
          } catch (ClassNotFoundException ex) {
              java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, null, ex);
          }
          addRestResourceClasses(resources);
          return resources;
      }
  </code></pre>
  
  <p>The problem now is, that my resources which generate Json should use jackson 2.3 annotations.
  But my glassfish uses some codehaus. ... packages to provide json. codehaus is the old version of jackson. I want to use the new one from fasterxml which provides the @JsonIdentityInfo annotation.</p>
  
  <p>I thought that i could solve my problem by writing:</p>
  
  <pre><code>@javax.ws.rs.ApplicationPath("resources")
  public class ApplicationConfig extends Application {
  
      @Override
      public Set&lt;Class&lt;?&gt;&gt; getClasses() {
          Set&lt;Class&lt;?&gt;&gt; resources = new java.util.HashSet&lt;Class&lt;?&gt;&gt;();
  
          resources.add(JacksonFeatures.class);  //from the com.fasterxml.jackson.jaxrs.annotation Package
          resources.add(JacksonJaxbJsonProvider.class);
          resources.add(JacksonJsonProvider.class);
  
          addRestResourceClasses(resources);
          return resources;
      }
  </code></pre>
  
  <p>But no effect. Now Glassfish uses the standard JsonProvider Moxy... which i dont want to use. Do you have any tips how i can force glassfish to use my library instead of the buildin-libraries? Or can i change the buildin library to the newer one?</p>
  
  <hr>
  
  <p>And if you know how to solve this. could you please provide a little code-snippet?</p>
  
  <hr>
  
  <h2>EDIT 1:</h2>
  
  <hr>
  
  <p>After trying the first approach to solve it:</p>
  
  <p>new ApplicationConfig:</p>
  
  <pre><code>@javax.ws.rs.ApplicationPath("resources")
  public class ApplicationConfig extends ResourceConfig {
  
      public ApplicationConfig() {
          //register( new GZipEncoder() );
          register( JacksonFeature.class );
      }
  
      private void addMyResources() {
          //a lot of resources.
      }
  
  }
  </code></pre>
  
  <p>JacksonFeature:</p>
  
  <pre><code>public class JacksonFeature implements Feature {
  
          public boolean configure( final FeatureContext context ) {
  
              String postfix = '.' + context.getConfiguration().getRuntimeType().name().toLowerCase();
  
              context.property( CommonProperties.MOXY_JSON_FEATURE_DISABLE + postfix, true );
  
              context.register( JsonParseExceptionMapper.class );
              context.register( JsonMappingExceptionMapper.class );
              context.register( JacksonJsonProvider.class, MessageBodyReader.class, MessageBodyWriter.class );
  
              return true;
          }
      }
  </code></pre>
  
  <p>pom:</p>
  
  <pre><code>&lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-annotations&lt;/artifactId&gt;
          &lt;version&gt;2.3.0&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.3.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.fasterxml.jackson.jaxrs&lt;/groupId&gt;
          &lt;artifactId&gt;jackson-jaxrs-base&lt;/artifactId&gt;
          &lt;version&gt;2.3.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.jersey.core&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-common&lt;/artifactId&gt;
          &lt;version&gt;2.4&lt;/version&gt;
          &lt;type&gt;jar&lt;/type&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.jersey.core&lt;/groupId&gt;
          &lt;artifactId&gt;jersey-server&lt;/artifactId&gt;
          &lt;version&gt;2.4&lt;/version&gt;
          &lt;type&gt;jar&lt;/type&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
          &lt;artifactId&gt;httpclient&lt;/artifactId&gt;
          &lt;version&gt;4.3&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
          &lt;artifactId&gt;httpcore&lt;/artifactId&gt;
          &lt;version&gt;4.3&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt;
          &lt;artifactId&gt;httpmime&lt;/artifactId&gt;
          &lt;version&gt;4.3&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.eclipse.persistence&lt;/groupId&gt;
          &lt;artifactId&gt;eclipselink&lt;/artifactId&gt;
          &lt;version&gt;2.5.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax&lt;/groupId&gt;
          &lt;artifactId&gt;javaee-web-api&lt;/artifactId&gt;
          &lt;version&gt;7.0&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>Dependencies:</p>
  
  <pre><code>http://i.stack.imgur.com/uA4V2.png
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>SEVERE:   Exception while loading the app : CDI deployment failure:WELD-001408 Unsatisfied dependencies for type [Ref&lt;ContainerRequest&gt;] with qualifiers [@Default] at injection point [[BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject org.glassfish.jersey.server.internal.routing.UriRoutingContext(Ref&lt;ContainerRequest&gt;, ProcessingProviders)]
  org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Ref&lt;ContainerRequest&gt;] with qualifiers [@Default] at injection point [[BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject org.glassfish.jersey.server.internal.routing.UriRoutingContext(Ref&lt;ContainerRequest&gt;, ProcessingProviders)]
      at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:403)
      at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:325)
      at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:177)
      ...
  </code></pre>
  
  <p>or</p>
  
  <pre><code>SEVERE:   Exception while loading the app
  SEVERE:   Undeployment failed for context /blueserver
  INFO:   file:/C:/bluetrail/blueserver/target/blueserver-0.0.0.1/WEB-INF/classes/_de.bluetrail_blueserver_war_0.0.0.1PU logout successful
  SEVERE:   Exception while loading the app : CDI deployment failure:WELD-001408 Unsatisfied dependencies for type [IterableProvider&lt;InjectionResolver&lt;Object&gt;&gt;] with qualifiers [@Default] at injection point [[BackedAnnotatedParameter] Parameter 2 of [BackedAnnotatedConstructor] @Inject org.glassfish.jersey.internal.inject.JerseyClassAnalyzer(@Named ClassAnalyzer, IterableProvider&lt;InjectionResolver&lt;Object&gt;&gt;)]
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>i will now post some classes of my project. In that classes i included all Annotations that i use.</p>
  
  <p>i have like 16 entities like that:</p>
  
  <pre><code>import com.fasterxml.jackson.annotation.JsonIdentityInfo;
  import com.fasterxml.jackson.annotation.ObjectIdGenerators;
  import java.io.Serializable;
  import java.sql.Timestamp;
  import java.util.Set;
  import javax.persistence.Entity;
  import javax.persistence.FetchType;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.ManyToMany;
  import javax.persistence.OneToOne;
  
  @Entity
  @JsonIdentityInfo(generator = ObjectIdGenerators.None.class, property = "id", scope=Address.class)
  //the JsonIdentityInfo is the reason i need Jackson 2
  public class Address implements Serializable {
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;
      private String postalCode;
      private String city;
      private String country;
      private String street;
      private String houseNumber;
      @Embedded
      private Coordinate coordinate;
      //getters, setters , etc.
  }
  </code></pre>
  
  <p>then i have a lot of DAO's like that:</p>
  
  <pre><code>import de.ibs.trail.entity.Address;
  import java.util.ArrayList;
  import java.util.List;
  import javax.ejb.Stateless;
  
  @Stateless
  public class AddressDao extends GenericDao {
      public Address getAddress(long id){
          return em.find(Address.class, id);
      }
  
      public List&lt;Address&gt; getAddresses(){
          List&lt;Address&gt; address = em.createQuery("SELECT a FROM Address a", Address.class).getResultList();
          return address;
      }
  }
  </code></pre>
  
  <p>and finally i have a lot of REssources like that:</p>
  
  <pre><code>import de.bluetrail.blueserver.dao.AddressDao;
  import de.ibs.trail.entity.Address;
  import java.util.List;
  import javax.ejb.Stateless;
  import javax.inject.Inject;
  import javax.ws.rs.GET;
  import javax.ws.rs.Path;
  import javax.ws.rs.PathParam;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.Context;
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.UriInfo;
  
  @Path("dummy")
  @Stateless
  public class DummyResource {
  
      @Context
      private UriInfo context;
      @Inject userAuth user;
      @Inject addressDao AddressDao;
  
      public DummyResource() {
      }
  
      @GET
      @Produces("application/json")
      public List&lt;Address&gt; getAddress() {
          return AddressDao.getAddresses();
      }
  
  }
  </code></pre>
  
  <p>Thats the first part. As a second part i have a class for some Google Services. Because i want to try to use some Google GeoLocation and Routing. I put the Google-Code into a pasteBin file, because its so huge:</p>
  
  <pre><code>http://pastebin.com/u3e0dms6
  </code></pre>
  
  <p>there i use libraries like:</p>
  
  <pre><code>import com.fasterxml.jackson.databind.ObjectMapper;
  import de.ibs.trail.entity.Address;
  //some other entities
  //...
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  import java.net.URLEncoder;
  import java.util.Iterator;
  import java.util.Set;
  import org.apache.http.HttpResponse;
  import org.apache.http.HttpStatus;
  import org.apache.http.StatusLine;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.methods.HttpGet;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.impl.client.DefaultHttpClient;
  </code></pre>
  
  <p>I hope that helps. All the other classes use the same annotations.</p>