|
1 | 1 | package org.kohsuke.github; |
2 | 2 |
|
3 | | -import com.fasterxml.jackson.databind.*; |
4 | | -import com.fasterxml.jackson.databind.introspect.VisibilityChecker; |
5 | | -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; |
6 | 3 | import org.apache.commons.io.IOUtils; |
7 | 4 | import org.kohsuke.github.authorization.AuthorizationProvider; |
8 | 5 | import org.kohsuke.github.authorization.UserAuthorizationProvider; |
9 | 6 | import org.kohsuke.github.connector.GitHubConnector; |
10 | 7 | import org.kohsuke.github.connector.GitHubConnectorRequest; |
11 | 8 | import org.kohsuke.github.connector.GitHubConnectorResponse; |
12 | 9 | import org.kohsuke.github.function.FunctionThrows; |
| 10 | +import tools.jackson.databind.DeserializationFeature; |
| 11 | +import tools.jackson.databind.InjectableValues; |
| 12 | +import tools.jackson.databind.MapperFeature; |
| 13 | +import tools.jackson.databind.ObjectReader; |
| 14 | +import tools.jackson.databind.ObjectWriter; |
| 15 | +import tools.jackson.databind.PropertyNamingStrategies; |
| 16 | +import tools.jackson.databind.json.JsonMapper; |
13 | 17 |
|
14 | 18 | import java.io.*; |
15 | 19 | import java.net.*; |
@@ -109,21 +113,34 @@ static class RetryRequestException extends IOException { |
109 | 113 | /** The Constant DEFAULT_MINIMUM_RETRY_TIMEOUT_MILLIS. */ |
110 | 114 | private static final int DEFAULT_MINIMUM_RETRY_MILLIS = DEFAULT_MAXIMUM_RETRY_MILLIS; |
111 | 115 | private static final Logger LOGGER = Logger.getLogger(GitHubClient.class.getName()); |
112 | | - private static final ObjectMapper MAPPER = new ObjectMapper(); |
| 116 | + private static final JsonMapper MAPPER = JsonMapper.builder() |
| 117 | + // Use annotations and enable access to private fields |
| 118 | + .enable(MapperFeature.USE_ANNOTATIONS) |
| 119 | + .enable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS) |
| 120 | + .enable(MapperFeature.INFER_PROPERTY_MUTATORS) |
| 121 | + .enable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS) |
| 122 | + // Set visibility to detect all fields (including private fields) |
| 123 | + // This matches the original Jackson 2 config: new VisibilityChecker.Std(NONE, NONE, NONE, NONE, ANY) |
| 124 | + .changeDefaultVisibility(vc -> { |
| 125 | + return vc.withGetterVisibility(NONE) |
| 126 | + .withIsGetterVisibility(NONE) |
| 127 | + .withSetterVisibility(NONE) |
| 128 | + .withCreatorVisibility(NONE) |
| 129 | + .withFieldVisibility(ANY); |
| 130 | + }) |
| 131 | + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) |
| 132 | + // Jackson 3 enables these by default - disable to match Jackson 2.x behavior |
| 133 | + .disable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS) |
| 134 | + .disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES) |
| 135 | + .enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS) |
| 136 | + .propertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE) |
| 137 | + .build(); |
113 | 138 |
|
114 | 139 | private static final ThreadLocal<String> sendRequestTraceId = new ThreadLocal<>(); |
115 | 140 |
|
116 | 141 | /** The Constant GITHUB_URL. */ |
117 | 142 | static final String GITHUB_URL = "https://api.github.com"; |
118 | 143 |
|
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 | | - |
127 | 144 | @Nonnull |
128 | 145 | private static <T> GitHubResponse<T> createResponse(@Nonnull GitHubConnectorResponse connectorResponse, |
129 | 146 | @CheckForNull BodyHandler<T> handler) throws IOException { |
|
0 commit comments