Skip to content
Open
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@

<dependencyManagement>
<dependencies>
<!-- Jackson 2.x BOM - default implementation -->
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
Expand Down Expand Up @@ -114,6 +115,14 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- Jackson 3.x BOM - optional, for users who want to use Jackson 3 -->
<dependency>
<groupId>tools.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>3.0.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -138,6 +147,7 @@
</dependencyManagement>

<dependencies>
<!-- Jackson 2.x - required, default implementation -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down Expand Up @@ -196,6 +206,13 @@
<artifactId>commons-lang3</artifactId>
<version>3.19.0</version>
</dependency>
<!-- Jackson 3.x - optional, users can add to use Jackson 3 -->
<!-- Note: Java 8 date/time support is built into Jackson 3.x, no separate module needed -->
<dependency>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.github.npathai</groupId>
<artifactId>hamcrest-optional</artifactId>
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/org/kohsuke/github/GitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.kohsuke.github.authorization.ImmutableAuthorizationProvider;
import org.kohsuke.github.authorization.UserAuthorizationProvider;
import org.kohsuke.github.connector.GitHubConnector;
import org.kohsuke.github.internal.GitHubJackson;

import java.io.*;
import java.util.*;
Expand Down Expand Up @@ -379,6 +380,8 @@ private GitHub(GitHubClient client) {
* rateLimitChecker
* @param authorizationProvider
* a authorization provider
* @param jackson
* the Jackson implementation to use for JSON serialization
* @throws IOException
* Signals that an I/O exception has occurred.
*/
Expand All @@ -388,7 +391,8 @@ private GitHub(GitHubClient client) {
GitHubRateLimitHandler rateLimitHandler,
GitHubAbuseLimitHandler abuseLimitHandler,
GitHubRateLimitChecker rateLimitChecker,
AuthorizationProvider authorizationProvider) throws IOException {
AuthorizationProvider authorizationProvider,
GitHubJackson jackson) throws IOException {
if (authorizationProvider instanceof DependentAuthorizationProvider) {
((DependentAuthorizationProvider) authorizationProvider).bind(this);
} else if (authorizationProvider instanceof ImmutableAuthorizationProvider
Expand All @@ -408,7 +412,8 @@ private GitHub(GitHubClient client) {
rateLimitHandler,
abuseLimitHandler,
rateLimitChecker,
authorizationProvider);
authorizationProvider,
jackson);

// Ensure we have the login if it is available
// This preserves previously existing behavior. Consider removing in future.
Expand Down
39 changes: 38 additions & 1 deletion src/main/java/org/kohsuke/github/GitHubBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.kohsuke.github.authorization.ImmutableAuthorizationProvider;
import org.kohsuke.github.connector.GitHubConnector;
import org.kohsuke.github.connector.GitHubConnectorResponse;
import org.kohsuke.github.internal.DefaultGitHubJackson;
import org.kohsuke.github.internal.GitHubJackson;

import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -159,6 +161,8 @@ static GitHubBuilder fromCredentials() throws IOException {

private GitHubConnector connector;

private GitHubJackson jackson;

private GitHubRateLimitChecker rateLimitChecker = new GitHubRateLimitChecker();

private GitHubRateLimitHandler rateLimitHandler = GitHubRateLimitHandler.WAIT;
Expand Down Expand Up @@ -189,7 +193,8 @@ public GitHub build() throws IOException {
rateLimitHandler,
abuseLimitHandler,
rateLimitChecker,
authorizationProvider);
authorizationProvider,
jackson != null ? jackson : DefaultGitHubJackson.createDefault());
}

/**
Expand Down Expand Up @@ -277,6 +282,38 @@ public GitHubBuilder withEndpoint(String endpoint) {
return this;
}

/**
* Configures which Jackson implementation to use for JSON serialization/deserialization.
*
* <p>
* By default, Jackson 2.x is used. To use Jackson 3.x, create a Jackson 3 instance using
* {@link DefaultGitHubJackson#createJackson3()} and pass it to this method.
* </p>
*
* <h3>Example: Using Jackson 3.x</h3>
*
* <pre>
* GitHub github = new GitHubBuilder().withOAuthToken("token")
* .withJackson(DefaultGitHubJackson.createJackson3())
* .build();
* </pre>
*
* <p>
* <strong>Note:</strong> To use Jackson 3.x, you must add the Jackson 3 {@code tools.jackson.core:jackson-databind}
* dependency to your project.
* </p>
*
* @param jackson
* the Jackson implementation to use
* @return the GitHubBuilder
* @see DefaultGitHubJackson#createJackson2()
* @see DefaultGitHubJackson#createJackson3()
*/
public GitHubBuilder withJackson(GitHubJackson jackson) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't have something in the internal package a public method.
I'd suggest just having DefaultGitHubJackson control this and not provide a public method to control this.

this.jackson = jackson;
return this;
}

/**
* With jwt token GitHubBuilder.
*
Expand Down
Loading
Loading