Skip to content

Commit 1c92ad1

Browse files
Add docs about Spring and jakarta-json (#215) (#220)
Co-authored-by: Sylvain Wallez <sylvain@elastic.co>
1 parent 150a171 commit 1c92ad1

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

docs/installation.asciidoc

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ available at https://snapshots.elastic.co/maven/.
2626
dependencies {
2727
implementation 'co.elastic.clients:elasticsearch-java:{version}'
2828
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3'
29+
30+
// Needed only if you use the spring-dependency-management
31+
// and spring-boot Gradle plugins
32+
implementation 'jakarta.json:jakarta.json-api:2.0.1' //<1>
2933
}
3034
--------------------------------------------------
35+
<1> See <<spring-jakarta-json>> for additional details.
3136

3237
[discrete]
3338
[[maven]]
@@ -39,19 +44,43 @@ dependencies:
3944
["source","xml",subs="attributes+"]
4045
--------------------------------------------------
4146
<project>
42-
4347
<dependencies>
48+
4449
<dependency>
4550
<groupId>co.elastic.clients</groupId>
4651
<artifactId>elasticsearch-java</artifactId>
4752
<version>{version}</version>
4853
</dependency>
54+
4955
<dependency>
5056
<groupId>com.fasterxml.jackson.core</groupId>
5157
<artifactId>jackson-databind</artifactId>
5258
<version>2.12.3</version>
5359
</dependency>
54-
</dependencies>
5560
61+
<!-- Needed only if you use the spring-boot Maven plugin -->
62+
<dependency> <!--1-->
63+
<groupId>jakarta.json</groupId>
64+
<artifactId>jakarta.json-api</artifactId>
65+
<version>2.0.1</version>
66+
</dependency>
67+
68+
</dependencies>
5669
</project>
5770
--------------------------------------------------
71+
<1> See <<spring-jakarta-json>> for additional details.
72+
73+
74+
[discrete]
75+
[[spring-jakarta-json]]
76+
=== Spring Boot and jakarta.json
77+
78+
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.
79+
80+
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].
81+
82+
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.
83+
84+
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`.
85+
86+
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`.

0 commit comments

Comments
 (0)