Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -582,3 +582,8 @@ Alex Crowell (@alex-crowell)
* Reported #1127: `@JsonTypeInfo` with `EXTERNAL_PROPERTY` does not handle
arrays of polymorphic types
[3.3.0]

Seonwoo Jung (@seonwooj0810)
* Contributed #6144: Fix `withCreatorVisibility(ANY)` to also enable
implicit private single-arg scalar delegating constructors
[3.3.0]
4 changes: 4 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Versions: 3.x (for earlier see VERSION-2.x)
(on both serialization and deserialization) instead of confusing low-level error
(reported by Alex C)
(fix by @cowtowncoder, w/ Claude code)
#6144: `withCreatorVisibility(Visibility.ANY)` does not enable implicit
private single-arg (scalar) delegating constructors
(reported by @user)
(fix by @seonwooj0810)

3.2.1 (not yet released)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,9 +888,17 @@ private void _removeNonVisibleCreators(List<PotentialCreator> ctors)
Iterator<PotentialCreator> it = ctors.iterator();
while (it.hasNext()) {
PotentialCreator ctor = it.next();
boolean visible = (ctor.paramCount() == 1)
? _visibilityChecker.isScalarConstructorVisible(ctor.creator())
: _visibilityChecker.isCreatorVisible(ctor.creator());
boolean visible;
if (ctor.paramCount() == 1) {
// For single-arg constructors, accept if EITHER scalar-constructor
// visibility OR general creator visibility is satisfied.
// This allows `withCreatorVisibility(Visibility.ANY)` to restore
// Jackson 2 behaviour where private scalar constructors were accepted.
visible = _visibilityChecker.isScalarConstructorVisible(ctor.creator())
|| _visibilityChecker.isCreatorVisible(ctor.creator());
} else {
visible = _visibilityChecker.isCreatorVisible(ctor.creator());
}
if (!visible) {
it.remove();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ static class PrivateBeanNonAnnotated {
private PrivateBeanNonAnnotated(String a) { this.a = a; }
}

// [databind#6144]: private long/String delegating ctors with creatorVisibility(ANY)
static class PrivateLongDelegating {
public long longValue;
public String stringValue;
public PrivateLongDelegating() {}
private PrivateLongDelegating(long v) { this.longValue = v; }
private PrivateLongDelegating(String v) { this.stringValue = v; }
}

// test for [databind#1347], config overrides for visibility
@JsonPropertyOrder(alphabetic=true)
static class Feature1347SerBean {
Expand Down Expand Up @@ -146,6 +155,28 @@ public void testPrivateDelegatingCtor() throws Exception
assertEquals("xyz", bean.a);
}

// [databind#6144]: withCreatorVisibility(ANY) should enable private scalar (long/String)
// delegating constructors, matching Jackson 2 behaviour
@Test
public void testPrivateLongDelegatingCtorWithCreatorVisibilityAny() throws Exception
{
// default: both private scalar constructors are not visible
assertThrows(JacksonException.class,
() -> MAPPER.readValue("2", PrivateLongDelegating.class));
assertThrows(JacksonException.class,
() -> MAPPER.readValue(q("hi"), PrivateLongDelegating.class));

// but when creatorVisibility is ANY, private scalar ctors should be accepted
ObjectMapper m = jsonMapperBuilder()
.changeDefaultVisibility(vc -> vc.withCreatorVisibility(Visibility.ANY))
.build();
PrivateLongDelegating fromLong = m.readValue("42", PrivateLongDelegating.class);
assertEquals(42L, fromLong.longValue);

PrivateLongDelegating fromString = m.readValue(q("hello"), PrivateLongDelegating.class);
assertEquals("hello", fromString.stringValue);
}

// [databind#1347]
@Test
public void testVisibilityConfigOverridesForSer() throws Exception
Expand Down