Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3906 by forcing Record constructors to be visible regardless of visibility overrides #3944

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,11 @@ public final VisibilityChecker<?> getDefaultVisibilityChecker(Class<?> baseType,
vc = VisibilityChecker.Std.allPublicInstance();
} else {
vc = getDefaultVisibilityChecker();
// 20-May-2023, tatu: [databind#3906] Must reset visibility for Records
// to avoid hiding Constructors
if (ClassUtil.isRecordType(baseType)) {
vc = vc.withCreatorVisibility(Visibility.NON_PRIVATE);
}
}
AnnotationIntrospector intr = getAnnotationIntrospector();
if (intr != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.fasterxml.jackson.databind.records;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.*;

// [databind#3906]
public class RecordCreatorVisibility3906Test extends BaseMapTest
{
// [databind#3906]
record Record3906(String string, int integer) { }

// [databind#3906]
public void testRecordCreatorVisibility3906() throws Exception {
ObjectMapper mapper = jsonMapperBuilder()
.visibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE)
.visibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
.build();
Record3906 recordTest_deserialized = mapper.readValue("{}", Record3906.class);
assertEquals(new Record3906(null, 0), recordTest_deserialized);
}
}