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
MediaType property binding issue in native builds #30491
Comments
In your case, it looks like the value given to I've reproduced a slightly different problem with the latest Spring Boot 3.0.x by adding the GraalVM and spring-data-rest starter, and binding to this property:
Here, the value is not incorrect but still cannot be converted to a The detailed exception shows that binding to
I'm moving this issue to Spring Boot for now - if it turns out this is not a binder issue, but a more general conversion issue in Spring Framework we will move it back here. |
hi and thanks for moving the issue, I wasn't sure where to put it. regarding your comment: this is exactly the issue I was referring to. Intuitively I would configure a media type with a slash I also added GraalVM ("GraalVM Native Support", as it's called in Spring Initializr), which gives me the additional gradle task Apparently, when using a native build, the constructor expects a media type with a dash Ideally jvm and native build would use the same constructor to accept the same format. I put together a minimal test case for you: https://github.com/mockxe/native-property-issue
Please see the test cases README.md for further information I hope this information helps you. |
On the JVM, the creation of the
|
Hello! I'd like to contribute here, it's my first time 😇. Is it possible ? |
|
The problem's occurring because static class PropertyEditorRuntimeHints implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
hints.reflection().registerType(MediaTypeEditor.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
}
} This registrar must be imported using |
It doesn't explain the difference I posted above. |
@quaff I'm not sure how that difference relates to this issue. If you don't use Spring Data REST then the |
@wilkinsona I'm using @mockxe's project, but |
Thanks, @quaff. With Spring Data REST on the classpath, the following reflection hints are generated:
When |
I was a bit nervous adding hints for all |
The dependency on spring-web from spring-beans makes it impossible to import the projects in Eclipse IDE due to cycles between projects. This commit therefore moves the web-related test for BeanUtilsRuntimeHints to spring-web. See gh-30491
The dependency on spring-web from spring-beans makes it impossible to import the projects in Eclipse IDE due to cycles between projects. This commit therefore moves the web-related test for BeanUtilsRuntimeHints to spring-web. See spring-projectsgh-30491
Affects: 6.0.8
issue description:
When setting a
org.springframework.http.MediaType
via config properties (e.g.application/json
) it works well when running in jvm, for example by./gradlew bootRun
. But when running natively, for example by./gradlew nativeRun
it fails on startup with a property binding issue:failed to convert java.lang.String to org.springframework.http.MediaType (caused by java.lang.IllegalArgumentException: Invalid token character '/' in token "application/json")
(full error below).It is possible to fix the native version by specifying the media type as
application-json
but this let's the jvm version fail on startup with a similar issue.This makes it hard to develop and debug on jvm and deploy as native image, when you use some general default config for both.
reproduce:
I encountered this when working with Spring Data REST, when I was setting
spring.data.rest.default-media-type
, but it also can be reproduced by setting up your own config properties which accept aMediaType
.full error when starting native build with
application/json
(bootRun works fine)full error when starting jvm build with
application-json
(nativeRun works fine)possible workarounds:
config.setDefaultMediaType()
If you like I can prepare a repository with a minimal test case.
Thanks for your work
The text was updated successfully, but these errors were encountered: