How to enable jackson on Payara 4.1.2.173/5.0.0.Alpha1

733 views
Skip to first unread message

Arnold Somogyi

unread,
Oct 9, 2017, 2:38:04 PM10/9/17
to Payara Forum
Hi, 

I am working on a JAX-RS rest project and I would like to use jackson for json marshalling/unmarshalling instead of MOXy because I am planning to use @JsonView(...) and withDefaultPrettyPrinter() fearures.

I have two issues, related to this topic.

1st issue:
I had to add the following extra method to my POJO for object to json conversation because by default Payara uses MOXy and I am not able to tell to Payara to use Jackson with the following configuration by default:

public String toJson() {
    try {
return new ObjectMapper().writer().withDefaultPrettyPrinter().writeValueAsString(this);
} catch (JsonProcessingException e) {
return String.format("<error: %s>", e.getMessage());
}
}

2nd issue:
I added @JsonView(View.MyView.class) to my POJO but the automatic marshalling does not consider View configuration:

@POST
@Path("/...")
@JsonView(View.MyView.class)
public List<MyType> hello() {
    List<MyType> myList = new ArrayList<>();
    ...
    return myList; 
}

So I need to do this hack:

@POST
@Path("/nearby")
public String hello() throws JsonProcessingException {
    List<MyType> myList = new ArrayList<>();

    // generate json response based on the view
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION);
    String json = mapper.writerWithView(View.MyView.class).writeValueAsString(ads);
    return json;
}

The relevnt part of my pom looks like this:
<dependencies>
    <!-- provided java EE api-->
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- message-body-writer for json media type -->
    <dependency>
        <groupId>com.fasterxml.jackson.jaxrs</groupId>
        <artifactId>jackson-jaxrs-json-provider</artifactId>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
        <version>2.26</version>
    </dependency>
</dependencies>

I also tried this, but it does not work either:

public class RestApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<Class<?>>();

// add jackson feature
classes.add(org.glassfish.jersey.jackson.JacksonFeature.class);

// add root resource
classes.add(MyRest.class);
return classes;
}
}


With Payara 4.1.2.173 I get the following exception:

[Payara 4.1] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=28 _ThreadName=http-thread-pool::http-listener-1(1)] [timeMillis: 1507570952317] [levelValue: 900] [[
  StandardWrapperValve[a.b.c.RestApplication]: Servlet.service() for servlet a.b.c.RestApplication threw exception
org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001334: Unsatisfied dependencies for type ObjectProvider<FilterProvider> with qualifiers @Default 


I read on the Payara website that 5.0.0 is going to use JSON Binding but my @JsonView setting is NOT applied.

Couldyou please help my to configure Payara properly?



Arnold Somogyi

unread,
Oct 9, 2017, 6:54:32 PM10/9/17
to Payara Forum
I also tried: "jersey.config.server.disableMoxyJson", true
It does not work :(

Ondro Mihályi

unread,
Oct 10, 2017, 8:21:40 AM10/10/17
to Payara Forum
Hi Arnold,

I believe you configured Jackson correctly, with the 2 maven dependencies and the feature registered in RestApplication. You should also avoid using ObjectMapper directly, instead provide a configured ObjectMapper to the Jackson feature using a provider - have a look at Jersey documentation about using Jackson: https://jersey.github.io/documentation/latest/media.html#json.jackson

Can you send the complete stacktrace of the UnsatisfiedResolutionException ? 

Ondro

Arnold Somogyi

unread,
Oct 10, 2017, 11:24:27 AM10/10/17
to Payara Forum
This is the full stack trace from the server.log file:

[2017-10-09T19:42:32.317+0200] [Payara 4.1] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=28 _ThreadName=http-thread-pool::http-listener-1(1)] [timeMillis: 1507570952317] [levelValue: 900] [[
  StandardWrapperValve[com.a.b.RestApplication]: Servlet.service() for servlet com.a.b.RestApplication threw exception
org.jboss.weld.exceptions.UnsatisfiedResolutionException: WELD-001334: Unsatisfied dependencies for type ObjectProvider<FilterProvider> with qualifiers @Default 
at org.jboss.weld.bean.builtin.InstanceImpl.get(InstanceImpl.java:107)
at org.glassfish.jersey.jackson.internal.FilteringJacksonJaxbJsonProvider.writeTo(FilteringJacksonJaxbJsonProvider.java:130)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.invokeWriteTo(WriterInterceptorExecutor.java:265)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:250)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
at org.glassfish.jersey.server.internal.JsonWithPaddingInterceptor.aroundWriteTo(JsonWithPaddingInterceptor.java:106)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:86)
at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1130)
at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:711)
at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:444)
at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:434)
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:329)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1606)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:258)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:654)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:593)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:371)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:480)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:180)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:539)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
at java.lang.Thread.run(Unknown Source)
]]

Ondrej Mihályi

unread,
Oct 10, 2017, 5:14:35 PM10/10/17
to Arnold Somogyi, Payara Forum
Hi,

I'm not sure exactly what's wrong here, but it seems that the something is triggering the FilteringJacksonJaxbJsonProvider which requires a CDI producer for ObjectProvider<FilterProvider>.

Try to find out why the FilteringJacksonJaxbJsonProvideris triggered - according to the JacksonFeature (https://github.com/jersey/jersey/blob/12e5d8bdf22bcd2676a1032ed69473cf2bbc48c7/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/JacksonFeature.java#L92), it gets triggered when some entity filtering is registered.

I haven't seen this before, therefore I can't be of any further help. With a standard configuration, I'm pretty sure that the filtering provider isn't turned on.

Ondro

--
You received this message because you are subscribed to the Google Groups "Payara Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to payara-forum+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/payara-forum/ccd328b3-5009-47a0-8bbe-7a67c4e5f937%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

youssef ghoubach

unread,
Nov 14, 2017, 9:39:44 AM11/14/17
to Payara Forum
Downgrade from <version>2.26</version> to <version>2.10.4</version> that resolved the problem for me
Reply all
Reply to author
Forward
0 new messages