Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yasson Module - JSON-B with Yasson #951

Open
MatthiasReining opened this issue Apr 15, 2019 · 8 comments
Open

Yasson Module - JSON-B with Yasson #951

MatthiasReining opened this issue Apr 15, 2019 · 8 comments

Comments

@MatthiasReining
Copy link

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" ?

@stoicflame
Copy link
Owner

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.

@stoicflame stoicflame added this to the 2.12.0 milestone Apr 16, 2019
@MatthiasReining
Copy link
Author

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.

@stoicflame
Copy link
Owner

You can force-enable by explicitly setting disabled to false:

<enunciate>
  <modules>
    <jackson disabled="false"/>

@MatthiasReining
Copy link
Author

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

@stoicflame
Copy link
Owner

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?

@MatthiasReining
Copy link
Author

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.

@stoicflame
Copy link
Owner

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.

@stoicflame stoicflame modified the milestones: 2.12.0, 2.13.0 Aug 8, 2019
@stoicflame
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants