-
-
Couldn't load subscription status.
- Fork 84
Description
We see the fowllowing.
In Weblogic, that uses Jersey to orchestrate rest web services, we can enable jackson to be used by.
-
javax.ws.rs.core.Application extend this class and set the property
proprties.put("jersey.config.server.disableMoxyJson", true); -
Include the jackson-jaxrs-providers
The problem now is the following.
We have unpredicatable behavior in terms of which of the Jackson providers get used.
In system tests, sometimes we see that the provider being used to render rest responses is:
com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider
Sometimes it is:
com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider
And this is very clear, when your rest web service uses as a response object a class that has JaxB annotations.
Sometimes the fields are rendered in the JSON as they are declared in the class. Some times the jaxb annotation metadata is being used some times ignored.
So if you image you a field called:
@xmlelement(name = "Field1")
String field1;
The json is sometimes rendered as field1 and other times as Filed1.
To me this looks like this boils down to however jersey decides to configure itself.
It goes hunting for classes that are providers or implemneting specific interfaces such as body writer and body readers, and then it is most likely chaos ruling your runtime echosystem.
I currently have no idea of what rest configuration is being activated, I just know it looks to be relatively random.
Are you aware of any approach by which it would be possible to say:
- I want to use JacksonJaxbJsonProvider all the time over JacksonJsonProvider.
I have seen that most of the time the configuration that is active for me is the one with the JacksonJaxbJsonProvider .
Therefore, I have tried as an experiment to froce my rest services to be handled by the JacksonJsonProvider.
To do this I tried
@Provider
@Consumes(MediaType.WILDCARD) // NOTE: required to support "non-standard" JSON variants
@Produces(MediaType.WILDCARD)
@Specializes
public class acksonRestProviderSpecialization extends JacksonJaxbJsonProvider{
public Wm6JacksonRestProviderSpecialization() {
super(JacksonJsonProvider.BASIC_ANNOTATIONS);
LOGGER.info("{} is being created,", this.getClass().getCanonicalName());
}
}
to see if I could knock out from CDI the JacksonJaxbJsonProvider.
But apparently Jersey still finds ount JacksonJaxbJsonProvider and still manages to use it.
Does anyone know how to ensure that the rest service provider used is the JacksonJaxbJsonProvider rather than the JacksonJsonProvider?