Fix reflection hint registration for @JsonMixins
The hints need to be registered for the mixin not the target of the mixin. Closes gh-32929
This commit is contained in:
@@ -98,7 +98,7 @@ class JsonMixinModuleEntriesBeanRegistrationAotProcessor implements BeanRegistra
|
||||
|
||||
private void contributeHints(RuntimeHints runtimeHints, JsonMixinModuleEntries entries) {
|
||||
Set<Class<?>> mixins = new LinkedHashSet<>();
|
||||
entries.doWithEntry(this.classLoader, (type, mixin) -> mixins.add(type));
|
||||
entries.doWithEntry(this.classLoader, (type, mixin) -> mixins.add(mixin));
|
||||
new BindingReflectionHintsRegistrar().registerReflectionHints(runtimeHints.reflection(),
|
||||
mixins.toArray(Class<?>[]::new));
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.function.BiConsumer;
|
||||
import org.assertj.core.api.InstanceOfAssertFactories;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.hint.MemberCategory;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
||||
import org.springframework.aot.test.generate.TestGenerationContext;
|
||||
@@ -62,8 +63,11 @@ class JsonMixinModuleEntriesBeanRegistrationAotProcessorTests {
|
||||
registerEntries(RenameMixInClass.class);
|
||||
processAheadOfTime();
|
||||
RuntimeHints runtimeHints = this.generationContext.getRuntimeHints();
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(Name.class, "getName")).accepts(runtimeHints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(NameAndAge.class, "getAge")).accepts(runtimeHints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(RenameMixInClass.class)
|
||||
.withMemberCategories(MemberCategory.DECLARED_FIELDS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS))
|
||||
.accepts(runtimeHints);
|
||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(RenameMixInClass.class, "getName").introspect())
|
||||
.accepts(runtimeHints);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -23,11 +23,9 @@ import org.springframework.boot.jackson.Name;
|
||||
import org.springframework.boot.jackson.NameAndAge;
|
||||
|
||||
@JsonMixin(type = { Name.class, NameAndAge.class })
|
||||
public class RenameMixInClass {
|
||||
public abstract class RenameMixInClass {
|
||||
|
||||
@JsonProperty("username")
|
||||
String getName() {
|
||||
return null;
|
||||
}
|
||||
public abstract String getName();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user