I have a web application deployed on Apache TomEE web profile 8.0.12. The application exposes a rest service that returns a json. The default library used from TomEE is Johnzon. I'm trying to change the default Johnzon json provider with the Jackson json provider.
To test the switch of the provider I have developed a rest service that returns a class with two strings, and one of the two strings is ignored using the Jackson @JsonIgnore annotation.
public class PropContainer {
@JsonIgnore
private String prop1;
private String prop2;
...
And a rest service that returns the PropContainer class
@Path("config")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Stateless
public class PreferencesService {
@Path("get")
@GET
@JacksonFeatures(serializationEnable = { SerializationFeature.INDENT_OUTPUT })
public PropContainer get(){
...
After invoking the service, the json is not formatted (the @JacksonFeatures is ignored) and prop1 attribute is in the response (the Jackson @JsonIgnore annotation is ignored). I think that TomEE is still using the Johnzon library.
Reading the TomEE documentation, the steps to change the json rest provider are:
- create the file openejb-jar.xml under src\main\webapp\WEB-INF\
- in openejb-jar.xml file specify the Jackson provider
<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar xmlns="http://www.openejb.org/openejb-jar/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openejb.org/openejb-jar/1.1">
<pojo-deployment class-name="jaxrs-application">
<properties>
cxf.jaxrs.providers = com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider
</properties>
</pojo-deployment>
</openejb-jar>
Any suggestions?
Thank you for the support.