Allow BeanSerializerModifier to override property serializers - #6173
Allow BeanSerializerModifier to override property serializers#6173hej090224 wants to merge 2 commits into
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 |
Code Review ✅ ApprovedAllows BeanSerializerModifier to override property serializers by updating BeanPropertyWriter.assignSerializer to permit intentional replacement of existing value serializers. No issues found. 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 |
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