Affects: 6.0.0-RC3
While looking at spring-projects/spring-boot#32929, I have learned that @RegisterReflectionForBinding generates incomplete reflection hints when using Jackson's @JsonProperty. This app illustrates the problem:
package com.example.demo;
import org.springframework.aot.hint.annotation.RegisterReflectionForBinding;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import com.example.demo.JsonPropertyApplication.Dto;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
@SpringBootApplication
@RegisterReflectionForBinding(Dto.class)
public class JsonPropertyApplication {
public static void main(String[] args) {
SpringApplication.run(JsonPropertyApplication.class, args);
}
@Bean
public CommandLineRunner commandLineRunner(ObjectMapper mapper) {
return (args) -> {
System.out.println(mapper.writeValueAsString(new Dto()));
};
}
static class Dto {
@JsonProperty
private String field = "test";
@JsonProperty
String packagePrivate() {
return "does it work?";
}
}
}
When run on the JVM, the following output if produced:
{"field":"test","packagePrivate":"does it work?"}
When run as a native image, the following output is produced:
Looking at BindingReflectionHintsRegistrar, I think there are a couple of problems here:
- Package-private (and private) methods are ignored
- Methods with names that don't look like getters or setters are ignored
Affects: 6.0.0-RC3
While looking at spring-projects/spring-boot#32929, I have learned that
@RegisterReflectionForBindinggenerates incomplete reflection hints when using Jackson's@JsonProperty. This app illustrates the problem:When run on the JVM, the following output if produced:
When run as a native image, the following output is produced:
Looking at
BindingReflectionHintsRegistrar, I think there are a couple of problems here: