users@jersey.java.net

[Jersey] Re: Jersey with Jackson for JSON

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Tue, 28 Jun 2011 20:46:10 +0200

Hi Charles,

You can leave the "com.sun.jersey.config.property.classpath" property
as is and add "com.sun.jersey.property.packages" init parameter to add
your application
packages to the configuration:

<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>your.app.pkg</param-value>
</init-param>

another option would be to add your application classes directly, so
that you save
the time needed for scanning:

<init-param>
<param-name>com.sun.jersey.config.property.classnames</param-name>
<param-value>your.app.pkg.Res1, your.app.pkg.Res2</param-value>
</init-param>

Would this be sufficient?

Or you need to have both JSON providers active at the same time within a
single application?
Each processing a distinct set of classes?

~Jakub



On 06/22/2011 12:53 AM, charlesk wrote:
> 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.
>