Skip to content

Commit 068dd6d

Browse files
committed
review
1 parent f06c780 commit 068dd6d

5 files changed

Lines changed: 33 additions & 54 deletions

File tree

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

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,33 @@ public GitHubBuilder clone() {
211211
}
212212
}
213213

214+
/**
215+
* Configures the client to use Jackson 3.x for JSON serialization/deserialization.
216+
*
217+
* <p>
218+
* By default, Jackson 2.x is used. Call this method to use Jackson 3.x instead.
219+
* </p>
220+
*
221+
* <h3>Example</h3>
222+
*
223+
* <pre>
224+
* GitHub github = new GitHubBuilder().withOAuthToken("token").useJackson3().build();
225+
* </pre>
226+
*
227+
* <p>
228+
* <strong>Note:</strong> To use Jackson 3.x, you must add the Jackson 3 {@code tools.jackson.core:jackson-databind}
229+
* dependency to your project.
230+
* </p>
231+
*
232+
* @return the GitHubBuilder
233+
* @throws IllegalStateException
234+
* if Jackson 3.x is not available on the classpath
235+
*/
236+
public GitHubBuilder useJackson3() {
237+
this.jackson = DefaultGitHubJackson.createJackson3();
238+
return this;
239+
}
240+
214241
/**
215242
* Adds a {@link GitHubAbuseLimitHandler} to this {@link GitHubBuilder}.
216243
* <p>
@@ -282,38 +309,6 @@ public GitHubBuilder withEndpoint(String endpoint) {
282309
return this;
283310
}
284311

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-
317312
/**
318313
* With jwt token GitHubBuilder.
319314
*

src/main/java/org/kohsuke/github/internal/DefaultGitHubJackson.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
* GitHub github = new GitHubBuilder().withOAuthToken("token").build();
2020
*
2121
* // Using Jackson 3.x
22-
* GitHub github = new GitHubBuilder().withOAuthToken("token")
23-
* .withJackson(DefaultGitHubJackson.createJackson3())
24-
* .build();
22+
* GitHub github = new GitHubBuilder().withOAuthToken("token").useJackson3().build();
2523
* </pre>
2624
*
2725
* <h2>Jackson 3.x Dependencies</h2>

src/main/java/org/kohsuke/github/internal/GitHubJackson.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
*
2525
* <h2>Configuration</h2>
2626
* <p>
27-
* Use {@link org.kohsuke.github.GitHubBuilder#withJackson(GitHubJackson)} to configure which Jackson version to use:
27+
* Use {@link org.kohsuke.github.GitHubBuilder#useJackson3()} to configure the client to use Jackson 3.x:
2828
* </p>
2929
*
3030
* <pre>
3131
* // Use Jackson 3.x
32-
* GitHub github = new GitHubBuilder().withJackson(DefaultGitHubJackson.createJackson3()).build();
32+
* GitHub github = new GitHubBuilder().useJackson3().build();
3333
* </pre>
3434
*
3535
* @author Pierre Villard

src/main/java/org/kohsuke/github/internal/GitHubJackson3.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* </p>
4040
*
4141
* <pre>
42-
* GitHub github = new GitHubBuilder().withJackson(DefaultGitHubJackson.createJackson3()).build();
42+
* GitHub github = new GitHubBuilder().useJackson3().build();
4343
* </pre>
4444
*
4545
* @author Pierre Villard

src/test/java/org/kohsuke/github/GitHubJacksonTest.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
import org.junit.Test;
44
import org.kohsuke.github.internal.DefaultGitHubJackson;
5-
import org.kohsuke.github.internal.GitHubJackson;
65

76
import java.io.IOException;
87

98
import static org.hamcrest.CoreMatchers.*;
109

1110
/**
12-
* Tests for Jackson implementation selection via {@link GitHubBuilder#withJackson(GitHubJackson)}.
11+
* Tests for Jackson implementation selection via {@link GitHubBuilder#useJackson3()}.
1312
*/
1413
public class GitHubJacksonTest extends AbstractGitHubWireMockTest {
1514

@@ -33,19 +32,6 @@ public void testDefaultJacksonIsJackson2() throws IOException {
3332
assertThat(implementationName, startsWith("Jackson 2."));
3433
}
3534

36-
/**
37-
* Test that Jackson 2 can be explicitly configured via builder.
38-
*
39-
* @throws IOException
40-
* the io exception
41-
*/
42-
@Test
43-
public void testJackson2ViaBuilder() throws IOException {
44-
gitHub = getGitHubBuilder().withJackson(DefaultGitHubJackson.createJackson2()).build();
45-
String implementationName = gitHub.getClient().getJacksonImplementationName();
46-
assertThat(implementationName, startsWith("Jackson 2."));
47-
}
48-
4935
/**
5036
* Test that Jackson 3 can be configured via builder when available.
5137
*
@@ -55,7 +41,7 @@ public void testJackson2ViaBuilder() throws IOException {
5541
@Test
5642
public void testJackson3ViaBuilder() throws IOException {
5743
if (DefaultGitHubJackson.isJackson3Available()) {
58-
gitHub = getGitHubBuilder().withJackson(DefaultGitHubJackson.createJackson3()).build();
44+
gitHub = getGitHubBuilder().useJackson3().build();
5945
String implementationName = gitHub.getClient().getJacksonImplementationName();
6046
assertThat(implementationName, startsWith("Jackson 3."));
6147
}

0 commit comments

Comments
 (0)