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

[Backport 7.17] Add docs about Spring and jakarta-json #219

Merged
merged 1 commit into from
Mar 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions docs/installation.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ available at https://snapshots.elastic.co/maven/.
dependencies {
implementation 'co.elastic.clients:elasticsearch-java:{version}'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3'

// Needed only if you use the spring-dependency-management
// and spring-boot Gradle plugins
implementation 'jakarta.json:jakarta.json-api:2.0.1' //<1>
}
--------------------------------------------------
<1> See <<spring-jakarta-json>> for additional details.

[discrete]
[[maven]]
Expand All @@ -39,19 +44,43 @@ dependencies:
["source","xml",subs="attributes+"]
--------------------------------------------------
<project>

<dependencies>

<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>{version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.12.3</version>
</dependency>
</dependencies>

<!-- Needed only if you use the spring-boot Maven plugin -->
<dependency> <!--1-->
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.0.1</version>
</dependency>

</dependencies>
</project>
--------------------------------------------------
<1> See <<spring-jakarta-json>> for additional details.


[discrete]
[[spring-jakarta-json]]
=== Spring Boot and jakarta.json

Spring Boot comes with Gradle and Maven plugins to ease development and dependency management. These plugins define built-in versions for a number of well-known libraries.

One these libraries is `jakarta.json:json-api` that defines the standard Java JSON API. In version `1.x` this library used the `javax.json` package, while in version `2.x` it uses the `jakarta.json` package after https://blogs.oracle.com/javamagazine/post/transition-from-java-ee-to-jakarta-ee[the transition from JavaEE to JakartaEE].

The {java-client} depends on version `2.0.1` of this library, in order to use the newer and future-proof `jakarta.json` package. But Spring Boot's Gradle plugin (at least in version `2.6` and below) overrides the {java-client}'s dependency to use version `1.1.6` in the older `javax.json` namespace.

This is why you have to explicitly add the `jakarta.json:jakarta.json-api:2.0.1` dependency. Otherwise, this will result in the following exception at runtime: `java.lang.ClassNotFoundException: jakarta.json.spi.JsonProvider`.

If your application also requires `javax.json` you can add the `javax.json:javax.json-api:1.1.4` dependency, which is equivalent to `jakarta.json:jakarta.json-api:1.1.6`.