open-liberty: ContextResolver not working

Hi, I’m trying to test my project in openliberty, but I’m having some trouble with my ContextResolver, it simply doesn’t work.

Here is the Resolver:

@Provider
public class JsonConfiguration implements ContextResolver<Jsonb> {

    @Override
    public Jsonb getContext(Class<?> aClass) {
        return JsonbBuilder.newBuilder()
                .withConfig(new JsonbConfig()
                        .withPropertyVisibilityStrategy(new PrivateVisibilityJsonbStrategy()))
                .build();
    }

}

When I use the same code in Payara it works the way it should. Any hints of what could be wrong??

Tested using OpenLibery 18.0.0.3

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 25 (15 by maintainers)

Most upvoted comments

A second customer is requesting this new enhancement.

Just found this from this thread:

I am going to mark this issue as a request for enhancement. The spec does not require the built-in JSON-B provider to use a context resolver, but it is not a bad idea. I am going to mark this issue as a request for enhancement. The spec does not require the built-in JSON-B provider to use a context resolver, but it is not a bad idea.

Can you please provide a link? I was unable to find a spec.

While I surely believe you, I found some interesting places where ppl use it as granted:

So far I found these app servers to support this feature (just for reference for those who stumble over this):

  • Glassfish ✔️
  • Payara ✔️
  • (Open) Liberty ✖️
  • Wildfly 14 ✖️

HTH.

Here is the Jaxrs 2.1 spec: https://download.oracle.com/otn-pub/jcp/jaxrs-2_1-pfd-spec/jaxrs-2_1-pfd-spec.pdf

Section 4.2.4 details standard entity providers and specifically states that JAXB providers must use application supplied context resolvers:

“The implementation-supplied entity provider(s) for javax.xml.bind.JAXBElement and applicationsupplied JAXB classes MUST use JAXBContext instances provided by application-supplied context resolvers, see Section 4.3. If an application does not supply a JAXBContext for a particular type, the implementation-supplied entity provider MUST use its own default context instead.”

There is nothing about JSON providers.

Section 11.2.6 details the Java API for JSON Processing and doesn’t say anything about context resolvers. Section 11.2.7 details the Java API for JSON Binding and doesn’t say anything about context resolvers.

That being said, we believe that this is a nice feature and we are investigating how difficult it would be to add this functionality.

Just found this from this thread:

I am going to mark this issue as a request for enhancement. The spec does not require the built-in JSON-B provider to use a context resolver, but it is not a bad idea. I am going to mark this issue as a request for enhancement. The spec does not require the built-in JSON-B provider to use a context resolver, but it is not a bad idea.

Can you please provide a link? I was unable to find a spec.

While I surely believe you, I found some interesting places where ppl use it as granted:

So far I found these app servers to support this feature (just for reference for those who stumble over this):

  • Glassfish ✔️
  • Payara ✔️
  • (Open) Liberty ✖️
  • Wildfly 14 ✖️

HTH.

Hi Felipe, I’m not sure if that is bad doc, or if it is something that we do that CXF does not, but Liberty definitely supports automatic registration for @Provider annotated classes.

Regardless, we do not currently support modifying our provided JSON MessageBodyReader/MessageBodyWriter with a ContextResolver as per my previous update.

Got it @WhiteCat22, I was trying to check if I was able to change this behaviour, but I couldn’t, I don’t have experience with the OSGI, and don’t know how to look into the context before assign the Liberty JsonbProvider. 😅

Thanks @WhiteCat22, I’ll take a look in this class and see if I’m able to submit a PR. If I can understand and add this lookup, I do it.

You can see here: JsonBProvider.java that Liberty does not currently look at the Context when creating a Jsonb object for Liberty’s built in JsonB MessageBodyReader/MessageBodyWriter. I suspect that Payara does use the context to create their Jsonb object, but I am unfamiliar with their code.

I am going to mark this issue as a request for enhancement. The spec does not require the built-in JSON-B provider to use a context resolver, but it is not a bad idea. We will prioritize and work this issue as it fits into our release schedule. Alternatively, feel free to submit a pull request 😃

For now, you can either create your own MessageBodyReader/MessageBodyWriter or use the above workaround to solve your problem.