I’m building Unit tests for my EE9 application, and I would like to use the same libraries as the platform I run the app on (Payara 5). To do this, I’ve included payara-embedded-all as a test dependency.
When testing e.g. JsonB, calling JsonbBuilder.create() gives an exception: class org.eclipse.yasson.JsonBindingProvider cannot be cast to class jakarta.json.bind.spi.JsonbProvider
.
This is due to the included provider implementing javax.json.bind.spi.JsonbProvider
, not jakarta.json.bind.spi.JsonbProvider
.
What is the intended way to solve this issue?
Hi @RInnovalor,
If you could share a small reproducer app, it would help us investigate this problem and help provide you with a resolution. Can you provide a simple to follow scenario how to reproduce this on the latest release of Payara Community Edition? A reproducer should ideally follow the SSCCE rules: http://www.sscce.org/.
Thanks,
James
Hi @JamesHillyard ,
I’m not sure how to upload a sample project, so I’ll just past the relevant code as a comment.
Jakarta Rest Resource
import jakarta.json.bind.JsonbBuilder;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.Path;
@Path("/hello-world")
public class HelloResource {
@DELETE
public void testJsonB() {
JsonbBuilder.create();
}
}
Test Case
import org.junit.jupiter.api.Test;
class HelloResourceTest {
HelloResource helloResource = new HelloResource();
@Test
void testHelloResource() {
helloResource.testJsonB();
}
}
Pom.xml dependencies
<dependencies>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>3.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jakarta.json.bind</groupId>
<artifactId>jakarta.json.bind-api</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>fish.payara.extras</groupId>
<artifactId>payara-embedded-all</artifactId>
<version>5.2022.2</version>
</dependency>
</dependencies>
Running the test with this setup should give you the error I’m experiencing.
Thanks for your time helping me resolve this issue!
Hi @RInnovalor,
Thank for for providing that, no worries about uploading a project, those code snippets were easy to follow and I was able to reproduce the issue.
If you replace the jakarta.json.bind-api
dependency with the JSON-B reference implementation, Yasson, this fixes your issue.
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>yasson</artifactId>
<version>3.0.0</version>
</dependency>
Thanks,
James