-
Notifications
You must be signed in to change notification settings - Fork 225
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
Unable to use in a Java EE 8 environment (javax.json vs. jakarta.json) #55
Comments
I have posted a workaround involving the use of the Maven shade plugin to Stackoverflow. On the stackoverlow thread, it was suggested
Does that mean that the elasticsearch-java client is not meant to be used with Java EE 8? Right now, there is unfortunately no alternative to Java EE 8 for many business applications as Java EE 9 is still in preview stage for most (if not all?) application servers. Also, migrating from Java EE 8 to Java EE 9 is not trivial because Java EE 9 is not backwards compatible to Java EE 8. For example, Hibernate Validator takes the following approach:
|
Thanks for the report @matthiaswelz. The Java client is meant to be compatible with Java8+, including Java EE 8, but also looking forward, hence the use of the newer I agree with you that Glassfish using the same class for implementations of The context here is a bit different from that of Hibernate Validator as the purpose of elasticsearch-java is not to provide an implementation of a JEE spec and our versioning follows that of Elaticsearch versions. I see two approaches to solving this:
I'm leaning towards the first approach, as we can expect that |
Another strange thing: The maven website for the artifact org.glassfish:jakarta.json lists version 2.0.1 as current and links to https://github.com/eclipse-ee4j/jsonp . However, the source code in that repository does not seem to include the actual implementation and the maven coordinates are different too: Funnily enough, the
Not sure what's going on here - but it appears to me that there seem to be multiple artifacts claiming to be the "official" one. Also, I don't know which artifact provides the Are you sure the Maybe using |
@matthiaswelz I found out that Glassfish JSON-P, in its I've updated the project dependencies in PR #63, which should solve compatibility issue with JEE8. As a workaround until the next release, you may filter out Glassfish from Elasticsearch-Java's dependencies in your project and add Parsson as a replacement. |
The co.elastic.clients.json.JsonpMapper class already uses the "new"
jakarta.json.*
classes (which are implemented in org.glassfish:jakarta.json). This causes an issue when trying to use the elasticsearch client in an environment which still has the "old" implementation org.glassfish:javax.json on the classpath (which is the case for most if not any Java EE 8 application server).This is because there is a class "org.glassfish.json.JsonProviderImpl" in both org.glassfish:javax.json and org.glassfish:jakarta.json. One uses
javax.json
classes and the other one usesjakarta.json
classes.The elastic client now (in class
JsonValueParser
) simply callsjakarta.json.spi.JsonProvider.provider()
which basically calls:Class.forName("org.glassfish.json.JsonProviderImpl");
However, in an Java EE 8 environment, this will return the JsonProviderImpl from org.glassfish:javax.json because the classes unfortunately share the same name and package.
During runtime, this will lead to an exception:
I have created a post on StackOverflow to ask if there is any possibility to use both in the same application. However, I do not expect there to be a solution unless the implementation of the "new" "org.glassfish.json.JsonProviderImpl" (in org.glassfish:jakarta.json) is moved to a different package or renamed. (I am also not sure why the authors of org.glassfish:jakarta.json chose to reuse the same package and class name for the new version).
However, in order to use the Elastic Client in Java EE 8 environments, there should be some sort of workaround for the time being: Maybe there could be two builds - one using the jakarta.json.* classes and one using the javax.json.* classes (or potentially using the maven shade plugin).
Any ideas?
The text was updated successfully, but these errors were encountered: