Repository navigation
Allow BeanSerializerModifier to override property serializers - #6173
Conversation
|
The intended change seems to be |
|
Thanks, this is a valid concern. I reproduced it on the previous head by having a serializer modifier call I updated I also added a regression test for the rejected null assignment. The existing tests still cover non-null replacement and preservation of the annotation-provided null serializer. Verification passed with the focused tests, 155 related serializer/contextual/annotation/null/unwrapped/view tests, The fix is pushed as commit |
BeanSerializerModifier to override property serializers
|
Sounds good; thank you @exijn for contributing this! One thing before I can merge this: if we don't have CLA from you, we'd need one, as per: https://github.com/FasterXML/jackson/blob/main/CONTRIBUTING.md#paperwork and once we get it, I can do final review and get this merged. |
|
Hi @cowtowncoder, I’ve emailed my signed CLA to |
Code Review ✅ Approved🟡 Medium risk · Allows modifiers to replace assigned property serializers, changing serialized output behavior. Allows OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
|
Merged: thank you @exijn ! |
Summary
ValueSerializerModifier.changeProperties()(the 3.x equivalent ofBeanSerializerModifier) receivesBeanPropertyWriterinstances after annotation-based serializers have already been assigned. The existingassignSerializer()guard rejects replacing those serializers, so a modifier cannot change one annotated property without copying the writer.This change allows the existing public
BeanPropertyWriter.assignSerializer()extension point to replace an existing non-null value serializer while continuing to reject clearing an assigned serializer withnull. The separateassignNullSerializer()guard is unchanged, so a modifier can replace regular serialization while preserving an explicitly configured null serializer.Rejecting
nullassignment preserves the_serializer/_dynamicSerializersinvariant: writers with no statically assigned serializer own a dynamic lookup map, while writers with an assigned serializer do not.No new public API is added. The change is binary compatible; the behavior of
assignSerializer()changes only to permit intentional non-null replacement of an existing value serializer.Tests
PropertySerializerModifier4385Test: verifies one of two same-type properties is replaced, annotation serializer precedence is changed only for the selected property, global/type serializers and other properties are unaffected, the annotation null serializer is preserved, and null assignment is rejected../mvnw.cmd -B -ntp clean verify: 6,222 tests passed, 0 failures, 0 errors, 1 skipped../mvnw.cmd -B -q -ff -ntp -DskipTests animal-sniffer:check: passed.git diff --check: passed.Fixes #4385