users@jersey.java.net

[Jersey] Re: Own _at_Provider with Jackson INDENT_OUTPUT

From: Jack Lista <jackalista_at_gmail.com>
Date: Mon, 13 Jan 2014 15:39:39 -0800

Hi Michal,

I suspect that I may be doing something like what Simon is doing in terms
of confusing some of my JSON configuration related to jackson, and I'm
trying to turn on server log file tracing to get some further detail about
what's being used for JSON databinding but I'm not seeing any actual
logging even though there's talk in the docs about a dedicated java
logger.

I set these in my Application class (descended from ResourceConfig):

property("jersey.config.server.tracing", "ALL").
property("jersey.config.server.tracing.threshold", "VERBOSE");

Sorry to ask bonehead questions, but can you tell me what else needs to be
done before this "dedicated" logger starts logging things? Thanks!!


On Mon, Jan 13, 2014 at 1:21 PM, Michal Gajdos <michal.gajdos_at_oracle.com>wrote:

> Hi Simon,
>
> you have dependency on both Jackson 1.x (via jersey-media-json-jackson)
> and Jackson 2.x (directly in your pom.xml). ObjectMapper class doesn't seem
> to be in the same package in Jackson 1
> (org.codehaus.jackson.map.ObjectMapper) than it is in Jackson 2 (
> com.fasterxml.jackson.databind.ObjectMapper). You have created
> ContextResolver for the latter (Jackson 2) but it's possible that Jackson 1
> is used to (un)marshall your entities (and ContextResolver is not found).
> Try to remove dependency on jersey-media-json-jackson (+ remove
> registration of JacksonFeature) and run your app again (MBR/MBW from
> Jackson 2 will still get registered via META-INF/services mechanism).
>
> Michal
>
>
> On 13.01.2014, 19:59 , Simon Herter wrote:
>
> Hi,
>
> I have some problems when using my own @Provider. I'm using Jackson for
> JSON processing and all works well but I can't figure out, how to modify
> the jackson content provider.
>
> I registered my own provider as shown in documentation (
> https://jersey.java.net/documentation/latest/media.html#json.jackson)
> but the output does not change.
>
>
> @Provider
> @Produces(MediaType.APPLICATION_JSON)
> public class JsonProvider implements ContextResolver<ObjectMapper>{
>
> final ObjectMapper om;
>
> public JsonProvider() {
> om = new ObjectMapper();
> om.enable(SerializationFeature.INDENT_OUTPUT);
> }
>
> @Override
> public ObjectMapper getContext(Class<?> type) {
> return om;
> }
> }
>
>
>
> @ApplicationPath("/")
> public class App extends ResourceConfig {
>
> public SmartCampusServer() {
> packages("package");
> register(JsonProvider.class);
> register(JacksonFeature.class);
> }
> }
>
> I'm using recent stable versions of jackson and jersey.
> Full Code is available as maven project on github
> https://github.com/ne0h/proseminar2013/tree/jsonprovider/server/Java/SmartCampusServer/
>
> Simon Herter
>
>
>