Repository navigation
Catching missing reflection metadata for Jackson-serialised records before release? #14516
|
A native-image CLI of mine serialised every Java record in its JSON output as Is there a better way to catch this class of problem before release? The tracing agent only sees the paths the tests exercise. Is there a build-time option that warns when a type is serialised reflectively but not registered, or a recommended way to fail fast when Jackson finds no accessors on a record? Context, if useful: https://github.com/jameskomo/docswatcher (fix in v0.3.0). |
Replies: 1 comment 1 reply
|
Yes. What bit you is the default (lenient) reflection handling: calls like 1. Build with native-image --exact-reachability-metadata ...With this flag, missing metadata no longer degrades silently. The binary throws a Note the scoping: 2. Make tests fail loudly at run time Libraries sometimes catch ./my-cli -XX:MissingRegistrationReportingMode=Exit ...
3. Run the real test suite as a native image Your smoke test only checked exit codes. The GraalVM Native Build Tools plugins can compile and run your JUnit tests as a native binary ( The tracing agent is still useful to generate the initial |
Yes. What bit you is the default (lenient) reflection handling: calls like
Class.getRecordComponents()orgetDeclaredMethods()on an unregistered type don't fail, they just come back without the members, so Jackson finds no accessors and writes{}. Native Image has a stricter mode for exactly this case.1. Build with
--exact-reachability-metadataWith this flag, missing metadata no longer degrades silently. The binary throws a
MissingReflectionRegistrationError(ajava.lang.Error) that names the exact element that was not registered.getRecordComponents(),getDeclaredMethods(),getDeclaredFields()and friends are all covered. See Reachability…