users@jersey.java.net

[Jersey] Re: Jersey with Jackson for JSON

From: charlesk <charlesk40_at_yahoo.com>
Date: Tue, 21 Jun 2011 15:53:12 -0700 (PDT)

Looks like I found a place in Jersey where Jackson providers are picked up.

This is in package com.sun.jersey.api.core.WebAppResourceConfig. If I don't
set the "com.sun.jersey.config.property.classpath" property, default path is
"WEB-INF/lib" and
  "WEB-INF/classes" as it is also explained as below.

So, this seems to make your application wars to use Jackson unless you
exclude the jackson providers in your .war file and the fact that providers
are chosen by just getting the first one from the list makes harder to
control which JSON serializers to use. Is there any Jersey configuration
options that I may be missing for people to either use Jackson or the
Jettison? So for example, I have below providers registered and I would
like to use yjava.ws.util.jaxb.JAXBContextResolver which use Jettison but
other people may want to use
org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider which is Jackson. If
there isn't a configuration option already, can we make one?

[class org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider,
class org.codehaus.jackson.jaxrs.JacksonJsonProvider,
class org.codehaus.jackson.jaxrs.JsonMappingExceptionMapper,
class org.codehaus.jackson.jaxrs.JsonParseExceptionMapper,
class yjava.ws.util.PaddedJSONProvider,
class yjava.ws.util.FormProvider,
class yjava.ws.util.jaxb.JAXBContextResolver,
class yjava.ws.util.jackson.ObjectMapperProvider,
class yjava.ws.util.jackson.YivJacksonJaxbJsonProviderWrapper,
class yjava.ws.util.ExceptionMapper,
class com.yahoo.sample.jaxbtest.JaxbTestResource]



/**
 * A mutable implementation of {_at_link DefaultResourceConfig} that
dynamically
 * searches for root resource and provider classes in the Web application
 * resource paths declared by the property
 * {_at_link ClasspathResourceConfig#PROPERTY_CLASSPATH}.
 * If that property is not included in the map of initial properties passed
to
 * the constructor then the Web application paths "WEB-INF/lib" and
 * "WEB-INF/classes" are utlized.

Scanning for root resource and provider classes in the Web app resource
paths:
  /WEB-INF/lib
  /WEB-INF/classes

Class that puts the providers (and the resource classes):
package com.sun.jersey.api.core.ScanningResourceConfig

    /**
     * Initialize and scan for root resource and provider classes
     * using a scanner.
     *
     * @param scanner the scanner.
     */
    public void init(final Scanner scanner) {
        this.scanner = scanner;

        final AnnotationScannerListener asl = new
PathProviderScannerListener();
        scanner.scan(asl);

        getClasses().addAll(asl.getAnnotatedClasses());
        
        if (LOGGER.isLoggable(Level.INFO) && !getClasses().isEmpty()) {
            final Set<Class> rootResourceClasses = get(Path.class);
            if (rootResourceClasses.isEmpty()) {
                LOGGER.log(Level.INFO, "No root resource classes found.");
            } else {
                logClasses("Root resource classes found:",
rootResourceClasses);
            }

            final Set<Class> providerClasses = get(Provider.class);
            if (providerClasses.isEmpty()) {
                LOGGER.log(Level.INFO, "No provider classes found.");
            } else {
                logClasses("Provider classes found:", providerClasses);
            }

        }
    }



--
View this message in context: http://jersey.576304.n2.nabble.com/Jersey-with-Jackson-for-JSON-tp6480924p6502154.html
Sent from the Jersey mailing list archive at Nabble.com.