Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
34 changes: 33 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;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private GitHubJackson jackson;
private GitHubJackson jackson = DefaultGitHubJackson.createDefault();


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());
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
jackson != null ? jackson : DefaultGitHubJackson.createDefault());
jackson);

}

/**
Expand All @@ -206,6 +211,33 @@ public GitHubBuilder clone() {
}
}

/**
* Configures the client to use Jackson 3.x for JSON serialization/deserialization.
*
* <p>
* By default, Jackson 2.x is used. Call this method to use Jackson 3.x instead.
* </p>
*
* <h3>Example</h3>
*
* <pre>
* GitHub github = new GitHubBuilder().withOAuthToken("token").useJackson3().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>
*
* @return the GitHubBuilder
* @throws IllegalStateException
* if Jackson 3.x is not available on the classpath
*/
public GitHubBuilder useJackson3() {
Copy link
Member

Choose a reason for hiding this comment

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

See comment on DefaultGitHubJackson.createDefault():

Suggested change
public GitHubBuilder useJackson3() {
public GitHubBuilder useJackson2() {

this.jackson = DefaultGitHubJackson.createJackson3();
return this;
}

/**
* Adds a {@link GitHubAbuseLimitHandler} to this {@link GitHubBuilder}.
* <p>
Expand Down
Loading
Loading