Skip to content

Commit af992cb

Browse files
authored
Merge pull request #189 from networknt/migrate-jackson-3
Migrate Lambda native to Jackson 3
2 parents 785235d + 6e4737e commit af992cb

13 files changed

Lines changed: 371 additions & 23 deletions

File tree

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
name: Jackson 3 source build
2+
on:
3+
pull_request:
4+
workflow_dispatch:
5+
inputs:
6+
source_refs:
7+
description: JSON map of prerequisite repositories to full commit SHAs
8+
type: string
9+
default: '{}'
10+
push:
11+
branches: [master]
12+
permissions:
13+
contents: read
14+
actions: read
15+
env:
16+
# Reviewed master policy and separately qualified candidate; both pins are immutable.
17+
JACKSON3_QUALIFIER_REVISION: f0d2100f972eec765b2b276e7ace38922394f0a6
18+
JACKSON3_CORE_REVISION: 97b2359b92ed3e1d05cac04f2da8760aa954e49d
19+
jobs:
20+
test:
21+
runs-on: ubuntu-latest
22+
timeout-minutes: 90
23+
steps:
24+
- uses: actions/checkout@v4
25+
with:
26+
path: consumer
27+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
28+
- uses: actions/setup-java@v4
29+
with:
30+
distribution: temurin
31+
java-version: '25'
32+
- uses: actions/checkout@v4
33+
with:
34+
repository: networknt/light-4j
35+
ref: ${{ env.JACKSON3_QUALIFIER_REVISION }}
36+
path: qualification-policy
37+
- name: Select qualified core and resolve remaining prerequisites
38+
id: prerequisites
39+
env:
40+
GH_TOKEN: ${{ github.token }}
41+
SOURCE_REFS: ${{ inputs.source_refs || '{}' }}
42+
shell: bash
43+
run: |
44+
jq -e --arg core "$JACKSON3_CORE_REVISION" --argjson expected '["http-client","json-overlay","light-4j","light-aws-lambda","light-rest-4j","openapi-parser","yaml-rule"]' '.["light-4j"] == $core and keys == $expected and all(.[]; type == "string" and test("^[0-9a-f]{40}$"))' consumer/ci/jackson3-source-refs.json >/dev/null
45+
source_refs=$(jq -c --argjson overrides "$SOURCE_REFS" '. * $overrides' consumer/ci/jackson3-source-refs.json)
46+
python3 qualification-policy/scripts/resolve_jackson3_consumer_sources.py \
47+
--core-sha "$JACKSON3_CORE_REVISION" \
48+
--repositories '{"json-overlay":null,"openapi-parser":null,"light-rest-4j":null,"light-aws-lambda":null}' --source-refs "$source_refs" \
49+
--report core-qualification.json --github-output "$GITHUB_OUTPUT"
50+
- uses: actions/checkout@v4
51+
with:
52+
repository: networknt/yaml-rule
53+
ref: ${{ steps.prerequisites.outputs.yaml_rule }}
54+
path: sources/yaml-rule
55+
- uses: actions/checkout@v4
56+
with:
57+
repository: networknt/http-client
58+
ref: ${{ steps.prerequisites.outputs.http_client }}
59+
path: sources/http-client
60+
- uses: actions/checkout@v4
61+
with:
62+
repository: networknt/light-4j
63+
ref: ${{ steps.prerequisites.outputs.light_4j }}
64+
path: sources/light-4j
65+
- uses: actions/checkout@v4
66+
with:
67+
repository: networknt/json-overlay
68+
ref: ${{ steps.prerequisites.outputs.json_overlay }}
69+
path: sources/json-overlay
70+
- uses: actions/checkout@v4
71+
with:
72+
repository: networknt/openapi-parser
73+
ref: ${{ steps.prerequisites.outputs.openapi_parser }}
74+
path: sources/openapi-parser
75+
- uses: actions/checkout@v4
76+
with:
77+
repository: networknt/light-aws-lambda
78+
ref: ${{ steps.prerequisites.outputs.light_aws_lambda }}
79+
path: sources/light-aws-lambda
80+
- uses: actions/checkout@v4
81+
with:
82+
repository: networknt/light-rest-4j
83+
ref: ${{ steps.prerequisites.outputs.light_rest_4j }}
84+
path: sources/light-rest-4j
85+
- name: Record source commits
86+
shell: bash
87+
run: |
88+
for source in consumer sources/*; do
89+
echo "$source $(git -C "$source" rev-parse HEAD)"
90+
done | tee source-commits.txt
91+
for source in sources/*; do
92+
printf '{"key":"%s","value":"%s"}\n' "${source##*/}" "$(git -C "$source" rev-parse HEAD)"
93+
done | jq -s from_entries | tee source-refs.json
94+
- name: Build prerequisites and run full tests
95+
shell: bash
96+
env:
97+
GH_TOKEN: ${{ github.token }}
98+
JACKSON3_REUSE_CORE_QUALIFICATION: 1
99+
JACKSON3_CORE_SOURCE: ${{ github.workspace }}/sources/light-4j
100+
JACKSON3_CORE_QUALIFICATION_REPORT: ${{ github.workspace }}/core-qualification.json
101+
JACKSON3_MAVEN_REPO: ${{ runner.temp }}/m2
102+
JACKSON3_YAML_RULE: ${{ github.workspace }}/sources/yaml-rule
103+
JACKSON3_HTTP_CLIENT: ${{ github.workspace }}/sources/http-client
104+
run: |
105+
set -euo pipefail
106+
bash qualification-policy/scripts/verify-jackson3-bootstrap.sh 2>&1 | tee source-build.log
107+
mvn -f sources/yaml-rule/pom.xml "-Dmaven.repo.local=$JACKSON3_MAVEN_REPO" clean install 2>&1 | tee -a source-build.log
108+
mvn -f sources/json-overlay/pom.xml "-Dmaven.repo.local=$JACKSON3_MAVEN_REPO" clean install 2>&1 | tee -a source-build.log
109+
mvn -f sources/openapi-parser/pom.xml "-Dmaven.repo.local=$JACKSON3_MAVEN_REPO" clean install 2>&1 | tee -a source-build.log
110+
mvn -f sources/light-rest-4j/pom.xml "-Dmaven.repo.local=$JACKSON3_MAVEN_REPO" clean install 2>&1 | tee -a source-build.log
111+
mvn -f sources/light-aws-lambda/pom.xml "-Dmaven.repo.local=$JACKSON3_MAVEN_REPO" clean install 2>&1 | tee -a source-build.log
112+
mvn -f consumer/pom.xml "-Dmaven.repo.local=$JACKSON3_MAVEN_REPO" clean install 2>&1 | tee -a source-build.log
113+
- name: Test native packaging script
114+
working-directory: consumer
115+
run: python3 tests/test_native_image_script.py
116+
- name: Build and invoke native Runtime locally
117+
working-directory: consumer
118+
env:
119+
MAVEN_REPO_LOCAL: ${{ runner.temp }}/m2
120+
run: |
121+
bash native-image-linux.sh
122+
python3 tests/native_runtime_smoke.py target/custom-runtime/lambda-native
123+
- name: Audit resolved artifacts, including releases and Jackson boundaries
124+
env:
125+
SOURCE_MAVEN_REPO: ${{ runner.temp }}/m2
126+
shell: bash
127+
run: |
128+
set -euo pipefail
129+
mvn -B -Dstyle.color=never -f consumer/pom.xml "-Dmaven.repo.local=$SOURCE_MAVEN_REPO" dependency:tree 2>&1 | tee resolved-dependencies.txt
130+
python3 sources/light-4j/scripts/jackson3_artifact_audit.py --repository "$SOURCE_MAVEN_REPO" --tree resolved-dependencies.txt --report artifact-audit.json --require-jackson3-only
131+
- uses: actions/upload-artifact@v4
132+
if: always()
133+
with:
134+
name: source-build-reports
135+
path: |
136+
source-build.log
137+
source-commits.txt
138+
source-refs.json
139+
resolved-dependencies.txt
140+
artifact-audit.json
141+
core-qualification.json
142+
**/target/surefire-reports/**
143+
**/target/*smoke*.log

‎README.md‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,43 @@ software.amazon.awssdk.services.lambda.model.ResourceNotFoundException: Function
122122

123123
### [AuditMiddleware](doc/audit.md)
124124
### [LambdaProxyMiddleware](doc/proxy.md)
125+
126+
## Jackson 3 migration
127+
128+
This source line uses Jackson 3.2.3 and json-schema-validator 3.0.8. Build the Jackson 3 light-4j, http-client, REST and AWS Lambda prerequisites first; older snapshot binaries are not compatible. Jackson annotations retain their com.fasterxml.jackson.annotation package.
129+
130+
The runtime mapper uses Jackson2Defaults with its existing permissive unknown-property override. Mapper instances are immutable. Java time and Optional support are built in. Classic SnakeYAML compatibility pins are retained until the stack-wide cleanup.
131+
132+
Local qualification includes the full JVM suite, sanitized event/validation parity against the Jackson 2 baseline, and an offline GraalVM 25 native-image build. A native-image build does not establish deployed AWS behavior or complete reflection coverage for every middleware/configuration. The separate conformance worktree is deferred.
133+
134+
Native qualification now invokes the executable against a synthetic loopback Lambda Runtime API:
135+
136+
```sh
137+
MAVEN_REPO_LOCAL=/path/to/isolated/m2 bash native-image-linux.sh
138+
python3 tests/native_runtime_smoke.py target/custom-runtime/lambda-native
139+
```
140+
141+
The smoke check binds an API Gateway event, runs the local health handler, and verifies success and builder-based error serialization. It uses no AWS endpoint or credentials. `-H:+AddAllCharsets` is required by SnakeYAML Engine's UTF-32 input detection. The check does not qualify every middleware chain or deployed AWS behavior.
142+
143+
### Reproducible Jackson 3 source build
144+
145+
`.github/workflows/jackson3-source-build.yml` builds the prerequisite source stack in an isolated Maven repository, reuses independently qualified full-core test evidence, and runs the prerequisite and full consumer suites. It pins reviewed policy `f0d2100f972eec765b2b276e7ace38922394f0a6` and candidate `97b2359b92ed3e1d05cac04f2da8760aa954e49d`; yaml-rule/http-client are selected from that verified evidence. The complete prerequisite closure is pinned in `ci/jackson3-source-refs.json`, initialized from the successful source-build manifest, with reviewed updates expressed as full SHAs; no default-branch or migration-branch lookup is used. Explicit `source_refs` replay overrides are merged into that map and remain subject to core qualification. The workflow uploads `source-refs.json`, `source-commits.txt`, `core-qualification.json` and Surefire reports. Core registration and workflow-token acceptance are merged in light-4j #2825 and #2826.
146+
147+
The optional `source_refs` workflow-dispatch input replays recorded full SHAs. GitHub enables dispatch only after the workflow exists on the default branch; before merge, reproduce from the recorded source checkouts locally. A green local suite is separate from a successful remote source-build run.
148+
149+
### Exact-source CI qualification
150+
151+
Consumer CI requires retained successful full-reactor evidence for the actual checked-out light-4j SHA and the same yaml-rule/http-client source commits. Core PR CI explicitly checks out the PR head, not its merge ref. Replay dispatches cannot qualify consumers. The attempt-specific evidence artifact records the actual checkout, prerequisite SHAs and test totals. A later pending, failed or cancelled run does not invalidate earlier valid evidence. All API pages and retained attempts are considered; missing or expired evidence blocks reuse. `core-qualification.json` records the accepted run and artifact.
152+
153+
The full dependency ledger is audited across all groups. Every NetworkNT release and snapshot must be source-installed, apart from the explicitly SHA-256-pinned Jackson 3 validator release. Known Jackson 2 yaml-rule and chaos-monkey releases are rejected even with a local-install marker. Jackson 2 dependencies in other groups are reported; ready migrations reject them except shared annotations.
154+
155+
156+
### Updating Jackson 3 sibling source pins after merge
157+
158+
The source manifest deliberately pins reviewed commits, including sibling PR sources. It does not follow branch heads. Later CI-only or documentation commits in a sibling do not require repeatedly chasing its head.
159+
160+
Before merging this dependent PR, merge networknt/light-aws-lambda#168. Resolve each actual merge commit through GitHub (`gh pr view <number> --repo networknt/<repo> --json mergeCommit`); do not substitute the old PR head or a moving branch. For codegen, merge and requalify the Lambda native dependency after AWS first.
161+
162+
Fetch each sibling repository’s master and verify the selected commit is its ancestor with `git merge-base --is-ancestor <merge-sha> origin/master`. Replace the corresponding values in `ci/jackson3-source-refs.json` with those full 40-character merge SHAs in a reviewed dependent change. Keep the remaining closure pins and the qualified core/policy SHAs unchanged. Run fresh source-build CI on that dependent commit and review its resolved-source artifact before merging. A squash or merge commit must be qualified even when its runtime tree matches the earlier pin.
163+
164+
For later sibling updates after this PR merges, use the same manifest-update PR and fresh dependent CI procedure. Never silently advance pins or infer qualification from the sibling’s own green build.

‎ci/jackson3-source-refs.json‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"http-client": "5ecee29dbb08d813512f5379c2e1b902d553c5d4",
3+
"json-overlay": "e309fd63f95317067c9b13a4bed7ac16727bfea5",
4+
"light-4j": "97b2359b92ed3e1d05cac04f2da8760aa954e49d",
5+
"light-aws-lambda": "dddbbc9e7f6f690f8688ceac024728b6a84f4808",
6+
"light-rest-4j": "a31955945036d9108b7e9bb72167415cc9cfc287",
7+
"openapi-parser": "9ae849056e49f7c796fe28bfe6093fbe4847cc5c",
8+
"yaml-rule": "c237cc3a25720f43e57bf571e25d5fa06687aa3b"
9+
}

‎native-image-linux.sh‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@ set -euo pipefail
33

44
cd -- "$(dirname -- "${BASH_SOURCE[0]}")"
55

6+
maven_args=()
7+
if [[ -n ${MAVEN_REPO_LOCAL:-} ]]; then
8+
maven_args+=("-Dmaven.repo.local=$MAVEN_REPO_LOCAL")
9+
fi
10+
if [[ ${MAVEN_OFFLINE:-0} == 1 ]]; then
11+
maven_args+=(-o)
12+
fi
13+
614
# Build the shaded JAR, then obtain its name and Java level from Maven.
7-
mvn clean install
15+
mvn clean install "${maven_args[@]}"
816
metadata_dir=$(mktemp -d)
917
trap 'rm -rf -- "$metadata_dir"' EXIT
10-
mvn -q help:evaluate -Dexpression=project.build.finalName \
18+
mvn -q help:evaluate "${maven_args[@]}" -Dexpression=project.build.finalName \
1119
-Doutput="$metadata_dir/final-name"
12-
mvn -q help:evaluate -Dexpression=maven.compiler.target \
20+
mvn -q help:evaluate "${maven_args[@]}" -Dexpression=maven.compiler.target \
1321
-Doutput="$metadata_dir/java-version"
1422
jar_name=$(cat "$metadata_dir/final-name")
1523
java_version=$(cat "$metadata_dir/java-version")
@@ -24,6 +32,7 @@ docker run --rm --user "$(id -u):$(id -g)" \
2432
"$graalvm_image" \
2533
--enable-url-protocols=http,https \
2634
--no-fallback \
35+
-H:+AddAllCharsets \
2736
--verbose \
2837
--initialize-at-build-time=org.slf4j,ch.qos.logback \
2938
--initialize-at-run-time=io.netty \

‎pom.xml‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@
8282
<maven.compiler.target>${java.version}</maven.compiler.target>
8383
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
8484
<version.light-4j>2.4.2-SNAPSHOT</version.light-4j>
85-
<version.json-schema-validator>2.0.8</version.json-schema-validator>
86-
<version.jackson>2.22.3</version.jackson>
85+
<version.json-schema-validator>3.0.8</version.json-schema-validator>
86+
<version.jackson>3.2.3</version.jackson>
8787
<version.slf4j>2.0.20</version.slf4j>
8888
<version.encoder>1.5.0</version.encoder>
8989
<version.lambda-core>1.4.0</version.lambda-core>
@@ -114,7 +114,7 @@
114114
<scope>import</scope>
115115
</dependency>
116116
<dependency>
117-
<groupId>com.fasterxml.jackson</groupId>
117+
<groupId>tools.jackson</groupId>
118118
<artifactId>jackson-bom</artifactId>
119119
<version>${version.jackson}</version>
120120
<type>pom</type>
@@ -356,15 +356,15 @@
356356
<version>${version.lambda-awssdk}</version>
357357
</dependency>
358358
<dependency>
359-
<groupId>com.fasterxml.jackson.core</groupId>
359+
<groupId>tools.jackson.core</groupId>
360360
<artifactId>jackson-databind</artifactId>
361361
</dependency>
362362
<dependency>
363-
<groupId>com.fasterxml.jackson.core</groupId>
363+
<groupId>tools.jackson.core</groupId>
364364
<artifactId>jackson-core</artifactId>
365365
</dependency>
366366
<dependency>
367-
<groupId>com.fasterxml.jackson.dataformat</groupId>
367+
<groupId>tools.jackson.dataformat</groupId>
368368
<artifactId>jackson-dataformat-yaml</artifactId>
369369
</dependency>
370370
<dependency>

‎src/main/java/com/networknt/aws/lambda/Main.java‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
44
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
5-
import com.fasterxml.jackson.databind.DeserializationFeature;
6-
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import tools.jackson.databind.DeserializationFeature;
6+
import tools.jackson.databind.ObjectMapper;
7+
import com.networknt.jackson.JacksonDefaults;
78
import com.networknt.aws.lambda.app.LambdaApp;
89

910
import java.io.IOException;
1011

1112

1213
public class Main {
13-
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
14-
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
14+
private static final ObjectMapper OBJECT_MAPPER = JacksonDefaults.builder()
15+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).build();
1516

1617
public static void main(String[] args) throws IOException {
1718

‎src/main/java/com/networknt/aws/lambda/handler/middleware/limit/LimitMiddleware.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
5-
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import tools.jackson.databind.ObjectMapper;
66
import com.networknt.aws.lambda.handler.MiddlewareHandler;
77
import com.networknt.aws.lambda.LightLambdaExchange;
88
import com.networknt.aws.lambda.utility.HeaderKey;

‎src/main/java/com/networknt/aws/lambda/handler/middleware/specification/OpenApiMiddleware.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.networknt.aws.lambda.handler.middleware.specification;
22

3-
import com.fasterxml.jackson.core.JsonProcessingException;
3+
import tools.jackson.core.JacksonException;
44
import com.networknt.aws.lambda.handler.MiddlewareHandler;
55
import com.networknt.aws.lambda.LightLambdaExchange;
66
import com.networknt.config.Config;
@@ -40,7 +40,7 @@ public OpenApiMiddleware() {
4040
String openapiString = Config.getInstance().getMapper().writeValueAsString(openapi);
4141
LOG.trace("OpenApiMiddleware openapiString: {}", openapiString);
4242
helper = new OpenApiHelper(openapiString);
43-
} catch (JsonProcessingException e) {
43+
} catch (JacksonException e) {
4444
LOG.error("merge specification failed");
4545
throw new RuntimeException("merge specification failed");
4646
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.networknt.aws.lambda;
2+
3+
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
4+
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
5+
import org.junit.jupiter.api.Test;
6+
import tools.jackson.databind.ObjectMapper;
7+
8+
import java.lang.reflect.Field;
9+
10+
import static org.junit.jupiter.api.Assertions.*;
11+
12+
class Jackson3NativeCompatibilityTest {
13+
private ObjectMapper mainMapper() throws Exception {
14+
Field field = Main.class.getDeclaredField("OBJECT_MAPPER");
15+
field.setAccessible(true);
16+
return (ObjectMapper) field.get(null);
17+
}
18+
19+
@Test
20+
void runtimeMapperKeepsPermissiveEventBinding() throws Exception {
21+
APIGatewayProxyRequestEvent event = mainMapper().readValue(
22+
"{\"path\":\"/v1/pets\",\"httpMethod\":\"POST\",\"futureField\":true} trailing",
23+
APIGatewayProxyRequestEvent.class);
24+
assertEquals("/v1/pets", event.getPath());
25+
assertEquals("POST", event.getHttpMethod());
26+
}
27+
28+
@Test
29+
void responseRetainsJackson2ShapeAndRoundTrips() throws Exception {
30+
ObjectMapper mapper = mainMapper();
31+
APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent()
32+
.withStatusCode(200).withBody("{\"ok\":true}").withIsBase64Encoded(false);
33+
String json = mapper.writeValueAsString(response);
34+
assertEquals("{\"statusCode\":200,\"headers\":null,\"multiValueHeaders\":null,"
35+
+ "\"body\":\"{\\\"ok\\\":true}\",\"isBase64Encoded\":false}", json);
36+
assertEquals(response, mapper.readValue(json, APIGatewayProxyResponseEvent.class));
37+
}
38+
39+
@Test
40+
void runtimeMapperRetainsJackson2StreamDepth() throws Exception {
41+
String nested = "[".repeat(600) + "0" + "]".repeat(600);
42+
assertDoesNotThrow(() -> mainMapper().readTree(nested));
43+
}
44+
}

0 commit comments

Comments
 (0)