-
Notifications
You must be signed in to change notification settings - Fork 769
Move to Jackson 3 #2173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Move to Jackson 3 #2173
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,13 +86,6 @@ | |
|
|
||
| <dependencyManagement> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.fasterxml.jackson</groupId> | ||
| <artifactId>jackson-bom</artifactId> | ||
| <version>2.20.0</version> | ||
| <type>pom</type> | ||
| <scope>import</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit</groupId> | ||
| <artifactId>junit-bom</artifactId> | ||
|
|
@@ -114,6 +107,19 @@ | |
| <type>pom</type> | ||
| <scope>import</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>tools.jackson</groupId> | ||
| <artifactId>jackson-bom</artifactId> | ||
| <version>3.0.3</version> | ||
| <type>pom</type> | ||
| <scope>import</scope> | ||
| </dependency> | ||
| <!-- Jackson 3.0 requires jackson-annotations 2.20 --> | ||
| <dependency> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete this and keep the |
||
| <groupId>com.fasterxml.jackson.core</groupId> | ||
| <artifactId>jackson-annotations</artifactId> | ||
| <version>2.20</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
|
|
@@ -138,14 +144,6 @@ | |
| </dependencyManagement> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.fasterxml.jackson.core</groupId> | ||
| <artifactId>jackson-databind</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.fasterxml.jackson.datatype</groupId> | ||
| <artifactId>jackson-datatype-jsr310</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.github.spotbugs</groupId> | ||
| <artifactId>spotbugs-annotations</artifactId> | ||
|
|
@@ -196,6 +194,10 @@ | |
| <artifactId>commons-lang3</artifactId> | ||
| <version>3.19.0</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>tools.jackson.core</groupId> | ||
| <artifactId>jackson-databind</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.github.npathai</groupId> | ||
| <artifactId>hamcrest-optional</artifactId> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| package org.kohsuke.github; | ||
|
|
||
| import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| import com.infradna.tool.bridge_method_injector.WithBridgeMethods; | ||
| import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
| import tools.jackson.databind.node.ObjectNode; | ||
|
|
||
| import java.io.IOException; | ||
| import java.time.Instant; | ||
|
|
@@ -174,7 +174,7 @@ public GHOrganization getOrganization() throws IOException { | |
| * if payload cannot be parsed | ||
| */ | ||
| public <T extends GHEventPayload> T getPayload(Class<T> type) throws IOException { | ||
| T v = GitHubClient.getMappingObjectReader(root()).readValue(payload.traverse(), type); | ||
| T v = GitHubClient.getMappingObjectReader(root()).forType(type).readValue(payload); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like |
||
| v.lateBind(); | ||
| return v; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,19 @@ | ||
| package org.kohsuke.github; | ||
|
|
||
| import com.fasterxml.jackson.databind.*; | ||
| import com.fasterxml.jackson.databind.introspect.VisibilityChecker; | ||
| import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
| import org.apache.commons.io.IOUtils; | ||
| import org.kohsuke.github.authorization.AuthorizationProvider; | ||
| import org.kohsuke.github.authorization.UserAuthorizationProvider; | ||
| import org.kohsuke.github.connector.GitHubConnector; | ||
| import org.kohsuke.github.connector.GitHubConnectorRequest; | ||
| import org.kohsuke.github.connector.GitHubConnectorResponse; | ||
| import org.kohsuke.github.function.FunctionThrows; | ||
| import tools.jackson.databind.DeserializationFeature; | ||
| import tools.jackson.databind.InjectableValues; | ||
| import tools.jackson.databind.MapperFeature; | ||
| import tools.jackson.databind.ObjectReader; | ||
| import tools.jackson.databind.ObjectWriter; | ||
| import tools.jackson.databind.PropertyNamingStrategies; | ||
| import tools.jackson.databind.json.JsonMapper; | ||
|
|
||
| import java.io.*; | ||
| import java.net.*; | ||
|
|
@@ -109,21 +113,34 @@ static class RetryRequestException extends IOException { | |
| /** The Constant DEFAULT_MINIMUM_RETRY_TIMEOUT_MILLIS. */ | ||
| private static final int DEFAULT_MINIMUM_RETRY_MILLIS = DEFAULT_MAXIMUM_RETRY_MILLIS; | ||
| private static final Logger LOGGER = Logger.getLogger(GitHubClient.class.getName()); | ||
| private static final ObjectMapper MAPPER = new ObjectMapper(); | ||
| private static final JsonMapper MAPPER = JsonMapper.builder() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| // Use annotations and enable access to private fields | ||
| .enable(MapperFeature.USE_ANNOTATIONS) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While the defaults have changed, I think all of these features and behavior were present in 2.x, correct? |
||
| .enable(MapperFeature.CAN_OVERRIDE_ACCESS_MODIFIERS) | ||
| .enable(MapperFeature.INFER_PROPERTY_MUTATORS) | ||
| .enable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS) | ||
| // Set visibility to detect all fields (including private fields) | ||
| // This matches the original Jackson 2 config: new VisibilityChecker.Std(NONE, NONE, NONE, NONE, ANY) | ||
| .changeDefaultVisibility(vc -> { | ||
| return vc.withGetterVisibility(NONE) | ||
| .withIsGetterVisibility(NONE) | ||
| .withSetterVisibility(NONE) | ||
| .withCreatorVisibility(NONE) | ||
| .withFieldVisibility(ANY); | ||
| }) | ||
| .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) | ||
| // Jackson 3 enables these by default - disable to match Jackson 2.x behavior | ||
| .disable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS) | ||
| .disable(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES) | ||
| .enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS) | ||
| .propertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE) | ||
| .build(); | ||
|
|
||
| private static final ThreadLocal<String> sendRequestTraceId = new ThreadLocal<>(); | ||
|
|
||
| /** The Constant GITHUB_URL. */ | ||
| static final String GITHUB_URL = "https://api.github.com"; | ||
|
|
||
| static { | ||
| MAPPER.registerModule(new JavaTimeModule()); | ||
| MAPPER.setVisibility(new VisibilityChecker.Std(NONE, NONE, NONE, NONE, ANY)); | ||
| MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
| MAPPER.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true); | ||
| MAPPER.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); | ||
| } | ||
|
|
||
| @Nonnull | ||
| private static <T> GitHubResponse<T> createResponse(@Nonnull GitHubConnectorResponse connectorResponse, | ||
| @CheckForNull BodyHandler<T> handler) throws IOException { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| package org.kohsuke.github; | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.databind.node.ArrayNode; | ||
| import org.junit.Test; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import tools.jackson.databind.JsonNode; | ||
| import tools.jackson.databind.json.JsonMapper; | ||
| import tools.jackson.databind.node.ArrayNode; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
|
|
@@ -80,7 +80,9 @@ public void testIfAllRequiredClassesAreRegisteredForAot() throws IOException { | |
|
|
||
| private Stream<String> readAotConfigToStreamOfClassNames(String reflectionConfig) throws IOException { | ||
| byte[] reflectionConfigFileAsBytes = Files.readAllBytes(Path.of(reflectionConfig)); | ||
| ArrayNode reflectConfigJsonArray = (ArrayNode) new ObjectMapper().readTree(reflectionConfigFileAsBytes); | ||
| ArrayNode reflectConfigJsonArray = (ArrayNode) JsonMapper.builder() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JsonMapper has existed since 2.11: |
||
| .build() | ||
| .readTree(reflectionConfigFileAsBytes); | ||
| return StreamSupport | ||
| .stream(Spliterators.spliteratorUnknownSize(reflectConfigJsonArray.iterator(), Spliterator.ORDERED), | ||
| false) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/FasterXML/jackson/blob/main/jackson3/MIGRATING_TO_JACKSON_3.md