enunciate
enunciate copied to clipboard
Yasson Module - JSON-B with Yasson
My current Java EE 8 app runs on Wildfly 16. I'm just using stock application server without defining a dedicated JAX-RS/JSON library. This mean the server use Yasson as JSON-B implementation. Therefore there is no dependency for Jackson on the project classpath.
Without a Jackson dependency enunciate render the data types of the JAX-RS interface just with (custom). Is there an option that the right objects are rendered also when using Yasson?
Are there plans for a "Module Yasson" beside "Jersey" and "Jackson" ?
There's currently no support for JSON-B/Yasson. That's a good enhancement request, though. I'll track it here.
In the meantime, you could force-enable the jackson module and see how well the data types get processed.
Thanks for having a look to Yasson :-)
I'm not sure, but for me it looks like that the jackson module have no forceEnable attribute. But when I link jackson dependency just to a mvn profile that generates the docu by the enunciate mvn plugin, the data types are detected and rendered. Therefore, this workaround could help.
You can force-enable by explicitly setting disabled
to false
:
<enunciate>
<modules>
<jackson disabled="false"/>
if i only set disabled
to false
the data type is just rendered as Custom ...
My workaround looks like that I add a mvn profile for generating the docu:
<profile>
<id>rest-api</id>
<dependencies>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- create and package rest api docu -->
<plugin>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-maven-plugin</artifactId>
<version>${enunciate.version}</version>
<executions>
<execution>
<phase>${phase-build-rest-api}</phase>
<goals>
<goal>docs</goal>
</goals>
<configuration>
<configFile>${basedir}/src/assembly/enunciate.xml</configFile>
</configuration>
</execution>
</executions>
<configuration>
<configFile>${basedir}/src/assembly/enunciate.xml</configFile>
</configuration>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${javaee.version}</version>
</dependency>
<dependency>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-lombok</artifactId>
<version>${enunciate.version}</version>
</dependency>
<dependency>
<groupId>dk.jyskebank.tooling.enunciate</groupId>
<artifactId>enunciate-openapi</artifactId>
<version>${enunciate-openapi.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>${assembly.plugin.version}</version>
<configuration>
<descriptors>
<descriptor>src/assembly/apidoc-assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>${phase-build-rest-api}</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
and start the generation within the Jenkins pipeline by
mvn com.webcohesion.enunciate:enunciate-maven-plugin:docs -Prest-api
Weird. With the module force-enabled, the run without the profile should be the same as the run with the profile. What's the difference between the profile and the non-profile configuration? Is it just the dependency on jackson
?
Yes. Without dependency the data type results always in Custom. I just use the profile to avoid the Jackson depency to my normal code base.
I put some effort into investigating the jackson
module enablement behavior. I can confirm that force-enabling the jackson module works, even with jackson not on the classpath. Here's a diff I applied to enunciate-sample to prove it:
diff --git a/enunciate.xml b/enunciate.xml
index b162cc0..cf578e9 100644
--- a/enunciate.xml
+++ b/enunciate.xml
@@ -16,6 +16,7 @@
<docs>
<download file="LICENSE" name="Apache II" description="The license governing this API" showLink="true"/>
</docs>
+ <jackson disabled="false"/>
<java-xml-client>
<package-conversions>
<convert from="com.ifyouwannabecool" to="com.ifyouwannabecool.client"/>
diff --git a/pom.xml b/pom.xml
index 08c659b..1b18337 100644
--- a/pom.xml
+++ b/pom.xml
@@ -75,12 +75,6 @@
<version>${jaxb.version}</version>
</dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.jaxrs</groupId>
- <artifactId>jackson-jaxrs-json-provider</artifactId>
- <version>${jackson.version}</version>
- </dependency>
-
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
diff --git a/src/main/java/com/ifyouwannabecool/App.java b/src/main/java/com/ifyouwannabecool/App.java
index 0d6d4db..000b14b 100644
--- a/src/main/java/com/ifyouwannabecool/App.java
+++ b/src/main/java/com/ifyouwannabecool/App.java
@@ -1,6 +1,5 @@
package com.ifyouwannabecool;
-import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.servlet.ServletProperties;
@@ -11,7 +10,6 @@ public class App extends ResourceConfig {
public App() {
packages(App.class.getPackage().getName(), "com.webcohesion.enunciate.rt");
- register(JacksonJsonProvider.class);
property(ServletProperties.FILTER_FORWARD_ON_404, true);
}
}
If you can modify that patch to expose the problem, I'd be happy to take another look. Although I'd suggest opening another thread if you find a bug or something. We'll keep this thread open to track Yasson support.
This enhancement is currently seeking a sponsor. If anybody is willing to sponsor the work, reach out to me and I'd be happy to pick it up.