Skip to content

Commit f06c780

Browse files
committed
Move to Jackson 3 - Phase 2
Design GitHubJackson interface with methods for reading/writing JSON Implement GitHubJackson2 and GitHubJackson3 Create DefaultGitHubJackson factory with programmatic selection Create GitHubJacksonException wrapper classes Add GitHubBuilder.withJackson() for configuring Jackson implementation Add testing infrastructure for both Jackson versions
1 parent 36f0922 commit f06c780

13 files changed

Lines changed: 980 additions & 75 deletions

pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686

8787
<dependencyManagement>
8888
<dependencies>
89+
<!-- Jackson 2.x BOM - default implementation -->
8990
<dependency>
9091
<groupId>com.fasterxml.jackson</groupId>
9192
<artifactId>jackson-bom</artifactId>
@@ -114,6 +115,14 @@
114115
<type>pom</type>
115116
<scope>import</scope>
116117
</dependency>
118+
<!-- Jackson 3.x BOM - optional, for users who want to use Jackson 3 -->
119+
<dependency>
120+
<groupId>tools.jackson</groupId>
121+
<artifactId>jackson-bom</artifactId>
122+
<version>3.0.4</version>
123+
<type>pom</type>
124+
<scope>import</scope>
125+
</dependency>
117126
<dependency>
118127
<groupId>junit</groupId>
119128
<artifactId>junit</artifactId>
@@ -138,6 +147,7 @@
138147
</dependencyManagement>
139148

140149
<dependencies>
150+
<!-- Jackson 2.x - required, default implementation -->
141151
<dependency>
142152
<groupId>com.fasterxml.jackson.core</groupId>
143153
<artifactId>jackson-databind</artifactId>
@@ -196,6 +206,13 @@
196206
<artifactId>commons-lang3</artifactId>
197207
<version>3.19.0</version>
198208
</dependency>
209+
<!-- Jackson 3.x - optional, users can add to use Jackson 3 -->
210+
<!-- Note: Java 8 date/time support is built into Jackson 3.x, no separate module needed -->
211+
<dependency>
212+
<groupId>tools.jackson.core</groupId>
213+
<artifactId>jackson-databind</artifactId>
214+
<optional>true</optional>
215+
</dependency>
199216
<dependency>
200217
<groupId>com.github.npathai</groupId>
201218
<artifactId>hamcrest-optional</artifactId>

src/main/java/org/kohsuke/github/GitHub.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.kohsuke.github.authorization.ImmutableAuthorizationProvider;
3131
import org.kohsuke.github.authorization.UserAuthorizationProvider;
3232
import org.kohsuke.github.connector.GitHubConnector;
33+
import org.kohsuke.github.internal.GitHubJackson;
3334

3435
import java.io.*;
3536
import java.util.*;
@@ -379,6 +380,8 @@ private GitHub(GitHubClient client) {
379380
* rateLimitChecker
380381
* @param authorizationProvider
381382
* a authorization provider
383+
* @param jackson
384+
* the Jackson implementation to use for JSON serialization
382385
* @throws IOException
383386
* Signals that an I/O exception has occurred.
384387
*/
@@ -388,7 +391,8 @@ private GitHub(GitHubClient client) {
388391
GitHubRateLimitHandler rateLimitHandler,
389392
GitHubAbuseLimitHandler abuseLimitHandler,
390393
GitHubRateLimitChecker rateLimitChecker,
391-
AuthorizationProvider authorizationProvider) throws IOException {
394+
AuthorizationProvider authorizationProvider,
395+
GitHubJackson jackson) throws IOException {
392396
if (authorizationProvider instanceof DependentAuthorizationProvider) {
393397
((DependentAuthorizationProvider) authorizationProvider).bind(this);
394398
} else if (authorizationProvider instanceof ImmutableAuthorizationProvider
@@ -408,7 +412,8 @@ private GitHub(GitHubClient client) {
408412
rateLimitHandler,
409413
abuseLimitHandler,
410414
rateLimitChecker,
411-
authorizationProvider);
415+
authorizationProvider,
416+
jackson);
412417

413418
// Ensure we have the login if it is available
414419
// This preserves previously existing behavior. Consider removing in future.

src/main/java/org/kohsuke/github/GitHubBuilder.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.kohsuke.github.authorization.ImmutableAuthorizationProvider;
66
import org.kohsuke.github.connector.GitHubConnector;
77
import org.kohsuke.github.connector.GitHubConnectorResponse;
8+
import org.kohsuke.github.internal.DefaultGitHubJackson;
9+
import org.kohsuke.github.internal.GitHubJackson;
810

911
import java.io.File;
1012
import java.io.FileInputStream;
@@ -159,6 +161,8 @@ static GitHubBuilder fromCredentials() throws IOException {
159161

160162
private GitHubConnector connector;
161163

164+
private GitHubJackson jackson;
165+
162166
private GitHubRateLimitChecker rateLimitChecker = new GitHubRateLimitChecker();
163167

164168
private GitHubRateLimitHandler rateLimitHandler = GitHubRateLimitHandler.WAIT;
@@ -189,7 +193,8 @@ public GitHub build() throws IOException {
189193
rateLimitHandler,
190194
abuseLimitHandler,
191195
rateLimitChecker,
192-
authorizationProvider);
196+
authorizationProvider,
197+
jackson != null ? jackson : DefaultGitHubJackson.createDefault());
193198
}
194199

195200
/**
@@ -277,6 +282,38 @@ public GitHubBuilder withEndpoint(String endpoint) {
277282
return this;
278283
}
279284

285+
/**
286+
* Configures which Jackson implementation to use for JSON serialization/deserialization.
287+
*
288+
* <p>
289+
* By default, Jackson 2.x is used. To use Jackson 3.x, create a Jackson 3 instance using
290+
* {@link DefaultGitHubJackson#createJackson3()} and pass it to this method.
291+
* </p>
292+
*
293+
* <h3>Example: Using Jackson 3.x</h3>
294+
*
295+
* <pre>
296+
* GitHub github = new GitHubBuilder().withOAuthToken("token")
297+
* .withJackson(DefaultGitHubJackson.createJackson3())
298+
* .build();
299+
* </pre>
300+
*
301+
* <p>
302+
* <strong>Note:</strong> To use Jackson 3.x, you must add the Jackson 3 {@code tools.jackson.core:jackson-databind}
303+
* dependency to your project.
304+
* </p>
305+
*
306+
* @param jackson
307+
* the Jackson implementation to use
308+
* @return the GitHubBuilder
309+
* @see DefaultGitHubJackson#createJackson2()
310+
* @see DefaultGitHubJackson#createJackson3()
311+
*/
312+
public GitHubBuilder withJackson(GitHubJackson jackson) {
313+
this.jackson = jackson;
314+
return this;
315+
}
316+
280317
/**
281318
* With jwt token GitHubBuilder.
282319
*

0 commit comments

Comments
 (0)