Skip to content

Commit

Permalink
Fix #3906 by forcing Record constructors to be visible regardless of …
Browse files Browse the repository at this point in the history
…overrides
  • Loading branch information
cowtowncoder committed May 21, 2023
1 parent 3140bb7 commit 6b441ed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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);
}
}

0 comments on commit 6b441ed

Please sign in to comment.