I am developing an application targeting a Java EE 8 application server (JBoss/Wildfly).
However, one of the dependencies (elasticsearch api) is already using jakarta.json.*
classes which results in a ClassCastException at runtime:
java.lang.ClassCastException: org.glassfish.json.JsonProviderImpl cannot be cast to jakarta.json.spi.JsonProvider
That is because the org.classfish.json.JsonProviderImpl
in my classpath (org.classfish:javax.json:1.1.4
) is still using javax.json classes.
However, as both org.glassfish:jakarta.json
and org.classfish:javax.json
define the same class org.classfish.json.JsonProviderImpl
(one using the javax.json.*
classes and one using the jakarta.json.*
classes...), I am unable to simply include both maven artifacts.
The implementation of JsonProviderImpl (in both artifacts!) basically returns the following by default:
return Class.forName("org.glassfish.json.JsonProviderImpl");
When both org.glassfish:jakarta.json
and org.classfish:javax.json
are on the classpath, this will cause issue for any of the implementations which will get the JsonProviderImpl
from the other package.
What can I do to resolve this?