Repository navigation
feat(java): apply JSON SKIP null handling to codec-decoded nulls - #4234
Open
pavel-ptashyts wants to merge 4 commits into
Open
pavel-ptashyts wants to merge 4 commits into
pavel-ptashyts wants to merge 4 commits into
Conversation
With onNullRead(SKIP) or onContentNullRead(SKIP), a Java null returned by the selected codec for a non-null JSON token is now treated like an explicit JSON null: the property keeps its current value (creator arguments stay absent), and the collection element, reference-array element, AtomicReferenceArray element, or map value is omitted. SET and FAIL are unchanged. Generated readers emit the null test only for SKIP properties, so default SET code is unchanged. Reference arrays compact decoded nulls after the read loop so graph-memory batch reservation stays ahead of each batch's final element. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Under content SKIP, a null decoded by an Any value codec is no longer put into the Any map or passed to the Any setter. Under property SKIP, an unwrapped child property (field or creator argument) is decoded before its group is created, so a decoded null does not publish an otherwise absent group. SET keeps the original group-then-read order. Also fix the read-side null handling guide, which still stated that codec nulls are never filtered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Interpreted creator reads filtered a null unboxed carrier under SKIP, while generated readers and property paths store carriers as decoded. Keep the decoded-null skip to the selected codec value only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pavel-ptashyts
requested review from
PragmaTwice,
chaokunyang and
theweipeng
as code owners
November 17, 2026 15:51
Contributor
Author
|
AI review artifact: Fory-guided reviewer (final round)
Review rounds
|
Contributor
Author
|
AI review artifact: independent general reviewer (final round)
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why?
onNullRead(SKIP)andonContentNullRead(SKIP)act only on an explicit JSONnulltoken. Anullthat the selected codec returns for a non-null JSON value is still assigned or inserted. Normalizing codecs (a trimming codec that maps" "tonull) therefore cannot rely onSKIP:{"id":"1","id":" "}clearsid, and["a"," "]with a trimmingelementCodecreads["a", null]. Dropping such elements today takes a complete custom collection codec per field type. Jackson'sNulls.SKIPtreats a deserializer-returnednulllike a JSONnullfor both properties and collection contents. Details in #4233.What does this PR do?
SKIP, a Javanulldecoded by the selected codec from a non-null JSON value is handled like an explicit JSONnull:failOnMissingRequiredPropertiesapply;JsonUnwrappedchild property or creator argument: decoded before its group is created, so a decodednulldoes not publish an otherwise absent group (same as an explicit JSONnull);Collection, object array orAtomicReferenceArray, map value, and Any value (Any map and Any setter, which follow the global content setting): not inserted / setter not called.SETandFAILare unchanged;FAILstill rejects only an explicit JSONnull. No new API.JsonFieldInfoassigns a decoded value through one small helper that returns early onnullunderSKIP.JsonCreatorFieldInfo.read*now store into the argument array (read*(reader, arguments)), so a skipped value leaves theMISSINGmarker in place; the 12ObjectCodeccall sites use it.AnyInfo.skipDecodedNullguards the 15 Any read sites. Unwrapped routes decode first only underSKIP;SETkeeps the group-then-read order. Unboxed carriers (value classes) are stored as decoded, as before, in every path.JsonReaderCodegenemits the null test only forSKIPproperties,SKIPcreator arguments that go through a codec (readResolvedField,assignCreatorValue), unwrappedSKIProutes, and Any values under contentSKIP. Generated code forSET/FAILis unchanged (checked withFORY_CODE_DIR).GenericCollectionCodec/ObjectCollectionCodecandGenericMapCodecskip the insertion; theSETArrayListfast path and the scalar-specialized collection and map codecs are untouched (their built-in element codecs never decodenullfrom a non-null token). Object arrays andAtomicReferenceArraydrop decodednulls in one pass after the read loop, only underSKIP, so each graph-memory batch is still reserved before the batch's final element is read; the reservation covers every decoded element.JsonProperty,NullHandling.SKIPandForyJsonBuilderJavadoc;docs/json/annotations.mdanddocs/json/custom-codecs.md(the sentence "A codec returning Java null after consuming a non-null token is not filtered" is replaced).JsonNullHandlingTest, both codegen modes, Latin1/UTF-16/UTF-8/stream inputs):decodedNullProperties: public field and setter keep their value underSKIPand are cleared underSET; a creator argument decoded tonullcounts as missing (failOnMissingRequiredPropertiesthrows) and an earlier duplicate is kept.customChildAndInvalidTargets:List,Set,String[],AtomicReferenceArraywith anelementCodecandMapwith avalueCodecdrop decodednulls; the defaultSETkeeps them.registeredElementCodec: a codec registered withregisterCodecfor an element type, as a property and as a rootList.decodedNullUnwrappedAndAny: unwrapped mutable and creator children stay absent, an earlier unwrapped value is kept; Any setter, Any map and creator Any map skip decoded nulls.decodedNullOutsideSkip: underSETandFAIL, decoded nulls are still assigned or inserted for every path above.propertyAssignments: the assertion that pinned the old behavior now checks that a decodednulldoes not overwrite an earlier value.Not covered, by design: primitive arrays with a custom element codec (a decoded
nullstill fails, as before),Optional/AtomicReferencecontent, and unboxed carriers. Their built-in or carrier codecs define their own null representation.Related issues
AI Contribution Checklist
yesyes, I included a completed AI Contribution Checklist in this PR description and the requiredAI Usage Disclosure.yes, my PR description includes the requiredai_reviewsummary and screenshot evidence or equivalent persisted links of the final clean AI review results from both fresh reviewers described inAI_POLICY.md, the Fory-guided reviewer and the independent general reviewer, on the current PR diff or current HEAD after the latest code changes.Completed checklist from
AI_POLICY.mdsection 9:yesAI Usage Disclosureblock below.AGENTS.mdand.agents/ci-and-pr.md, and one independent general reviewer in a separate clean-context review session that was not pointed to.agents/ci-and-pr.mdor any copied Fory-specific review checklist.Verification
JDK 21.0.2, Windows 11 x86_64, base
apache/mainc8bb610:java/at 193d2b8:mvn -pl fory-json spotless:check checkstyle:check test: 1341 tests, 0 failures; spotless and checkstyle clean.JsonNullHandlingTestfrom this branch run againstapache/mainsources: 8 failures (the new SKIP assertions, both codegen modes).decodedNullUnwrappedAndAnyalso fails on the first commit of this branch, before the Any/unwrapped fix.FORY_CODE_DIR) inspected: the decoded-null test and the deferred unwrapped group creation appear only in readers ofSKIPmodels.docs/json: prettier clean for the changed files.Does this PR introduce any user-facing change?
Behavior change: under
SKIP, anullreturned by a codec for a non-null JSON value is now skipped instead of assigned or inserted.SET(the default) andFAILare unchanged.Benchmark
The
JsonSerializationSuitemodel (eishayMediaContent, defaultSET, codegen on) does not reach any changed line: withSETthe generated readers are textually identical toapache/main(the 1186 generated classes ofJsonCreatorTest,JsonCollectionTest,JsonAnyPropertyTestandJsonUnwrappedTest, dumped withFORY_CODE_DIRand compared after normalizing class-number suffixes, show no difference),ArrayListfields keep theirSETfast path, andList<String>uses the scalar collection codec. The changed interpreted loops (GenericCollectionCodec/ObjectCollectionCodecfor non-ArrayListcollections,GenericMapCodec,JsonFieldInfoobject branch) gain one null comparison per value before an existing codec call.JMH,
JsonSerializationSuite.fory(To|From)Json(Bytes|String), JDK 21.0.2, Windows 11, 10 logical CPUs,-f 2 -wi 5 -w 2s -i 8 -r 2s, runs alternating base/patched, ops/ms:The host was shared with other workloads during these runs: the write benchmarks, which this PR does not touch, drift down by the same proportion as the read benchmarks, and the error bars overlap across runs 1-3. I read this as no measurable difference, and would rerun on a quiet host if maintainers want numbers for the record.
🤖 Generated with Claude Code