Skip to content

Commit 36f0922

Browse files
authored
Merge pull request #2182 from pvillard31/jackson-3-phase-1
Enable Jackson 3 - Phase 1
2 parents f748642 + 310774f commit 36f0922

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<dependency>
9090
<groupId>com.fasterxml.jackson</groupId>
9191
<artifactId>jackson-bom</artifactId>
92-
<version>2.20.0</version>
92+
<version>2.21.0</version>
9393
<type>pom</type>
9494
<scope>import</scope>
9595
</dependency>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public GHOrganization getOrganization() throws IOException {
174174
* if payload cannot be parsed
175175
*/
176176
public <T extends GHEventPayload> T getPayload(Class<T> type) throws IOException {
177-
T v = GitHubClient.getMappingObjectReader(root()).readValue(payload.traverse(), type);
177+
T v = GitHubClient.getMappingObjectReader(root()).forType(type).readValue(payload);
178178
v.lateBind();
179179
return v;
180180
}

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.databind.*;
44
import com.fasterxml.jackson.databind.introspect.VisibilityChecker;
5+
import com.fasterxml.jackson.databind.json.JsonMapper;
56
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
67
import org.apache.commons.io.IOUtils;
78
import org.kohsuke.github.authorization.AuthorizationProvider;
@@ -109,21 +110,19 @@ static class RetryRequestException extends IOException {
109110
/** The Constant DEFAULT_MINIMUM_RETRY_TIMEOUT_MILLIS. */
110111
private static final int DEFAULT_MINIMUM_RETRY_MILLIS = DEFAULT_MAXIMUM_RETRY_MILLIS;
111112
private static final Logger LOGGER = Logger.getLogger(GitHubClient.class.getName());
112-
private static final ObjectMapper MAPPER = new ObjectMapper();
113+
private static final ObjectMapper MAPPER = JsonMapper.builder()
114+
.addModule(new JavaTimeModule())
115+
.visibility(new VisibilityChecker.Std(NONE, NONE, NONE, NONE, ANY))
116+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
117+
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS)
118+
.propertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
119+
.build();
113120

114121
private static final ThreadLocal<String> sendRequestTraceId = new ThreadLocal<>();
115122

116123
/** The Constant GITHUB_URL. */
117124
static final String GITHUB_URL = "https://api.github.com";
118125

119-
static {
120-
MAPPER.registerModule(new JavaTimeModule());
121-
MAPPER.setVisibility(new VisibilityChecker.Std(NONE, NONE, NONE, NONE, ANY));
122-
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
123-
MAPPER.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true);
124-
MAPPER.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
125-
}
126-
127126
@Nonnull
128127
private static <T> GitHubResponse<T> createResponse(@Nonnull GitHubConnectorResponse connectorResponse,
129128
@CheckForNull BodyHandler<T> handler) throws IOException {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.kohsuke.github;
22

33
import com.fasterxml.jackson.databind.JsonNode;
4-
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.databind.json.JsonMapper;
55
import com.fasterxml.jackson.databind.node.ArrayNode;
66
import org.junit.Test;
77
import org.springframework.boot.test.context.SpringBootTest;
@@ -80,7 +80,9 @@ public void testIfAllRequiredClassesAreRegisteredForAot() throws IOException {
8080

8181
private Stream<String> readAotConfigToStreamOfClassNames(String reflectionConfig) throws IOException {
8282
byte[] reflectionConfigFileAsBytes = Files.readAllBytes(Path.of(reflectionConfig));
83-
ArrayNode reflectConfigJsonArray = (ArrayNode) new ObjectMapper().readTree(reflectionConfigFileAsBytes);
83+
ArrayNode reflectConfigJsonArray = (ArrayNode) JsonMapper.builder()
84+
.build()
85+
.readTree(reflectionConfigFileAsBytes);
8486
return StreamSupport
8587
.stream(Spliterators.spliteratorUnknownSize(reflectConfigJsonArray.iterator(), Spliterator.ORDERED),
8688
false)

src/test/java/org/kohsuke/github/internal/graphql/response/GHGraphQLResponseMockTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import com.fasterxml.jackson.core.JsonProcessingException;
44
import com.fasterxml.jackson.databind.DeserializationFeature;
55
import com.fasterxml.jackson.databind.JavaType;
6-
import com.fasterxml.jackson.databind.ObjectMapper;
76
import com.fasterxml.jackson.databind.ObjectReader;
7+
import com.fasterxml.jackson.databind.json.JsonMapper;
88
import org.junit.jupiter.api.Test;
99

1010
import java.util.List;
@@ -20,10 +20,9 @@
2020
class GHGraphQLResponseMockTest {
2121

2222
private GHGraphQLResponse<Object> convertJsonToGraphQLResponse(String json) throws JsonProcessingException {
23-
ObjectMapper objectMapper = new ObjectMapper();
24-
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
23+
JsonMapper mapper = JsonMapper.builder().disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build();
2524

26-
ObjectReader objectReader = objectMapper.reader();
25+
ObjectReader objectReader = mapper.reader();
2726
JavaType javaType = objectReader.getTypeFactory()
2827
.constructParametricType(GHGraphQLResponse.class, Object.class);
2928

0 commit comments

Comments
 (0)