Fix #6144: withCreatorVisibility(ANY) now enables private scalar delegating constructors - #6152
Open
seonwooj0810 wants to merge 1 commit into
Open
Conversation
…alar delegating constructors In Jackson 3, `_removeNonVisibleCreators` used only `isScalarConstructorVisible` (which checks the new `scalarConstructorMinLevel`, defaulting to NON_PRIVATE) for single-arg constructors. This meant that setting `withCreatorVisibility(Visibility.ANY)` — the natural Jackson 2→3 migration step — had no effect on implicit private scalar (long/String) constructors. Fix: for single-arg constructors, accept when EITHER `isScalarConstructorVisible` OR `isCreatorVisible` passes, so that `withCreatorVisibility(ANY)` restores the Jackson 2 behaviour where private scalar constructors were accepted implicitly. Default behaviour (NON_PRIVATE scalar + PUBLIC_ONLY creator) is unchanged because both conditions return false for private constructors under those defaults.
Member
|
I am not sure this is correct -- Scalar creator visibility check should be used in 3.x, not general-purpose one (unlike in 2.x). That is: Will add a note on #6144. |
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.
Problem
FasterXML/jackson-databind#6144In Jackson 3, implicit single-arg (scalar) constructors (
String,long, etc.) used asdelegating creators go through
_removeNonVisibleCreators, which checksisScalarConstructorVisibleagainst the newscalarConstructorMinLevelaxis (defaulting toNON_PRIVATE).When users migrate from Jackson 2 — where creator visibility defaulted to
ANY— the naturalfix attempt is
changeDefaultVisibility(vc -> vc.withCreatorVisibility(Visibility.ANY)).This has no effect on scalar constructors because
withCreatorVisibilitydoes not touch_scalarConstructorMinLevel, leaving private scalar constructors still filtered out.Repro
Fix
In
POJOPropertiesCollector._removeNonVisibleCreators, for single-arg constructors, accept wheneither
isScalarConstructorVisibleorisCreatorVisiblepasses:This means:
isScalarConstructorVisible(NON_PRIVATE) andisCreatorVisible(PUBLIC_ONLY) returnfalsefor private constructors — they are stillfiltered out.
withCreatorVisibility(ANY)now works:isCreatorVisiblereturnstruefor privateconstructors, so they are kept — restoring Jackson 2 migration behaviour.
withScalarConstructorVisibility(ANY)continues to work as before.Tests
Added
testPrivateLongDelegatingCtorWithCreatorVisibilityAnytoTestAutoDetect:regression).
withCreatorVisibility(ANY), both privatelongand privateStringconstructors work as implicit delegating creators.
All existing
TestAutoDetecttests pass.