-
Notifications
You must be signed in to change notification settings - Fork 472
BoundMethodParameter references static, default instance of ConversionService #118
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
Comments
Can you elaborate on the context of this request? The sole purpose of using a |
Well, you asked me to open it, so I'm hoping you remember why. I believe it had something to do with what happens when a user registers a custom |
|
+1 I'm using spring-data's
Now, when generating a link to a given
which gives me a link like Indeed, the path variable's string representation is statically resolved with the
I think it makes sense to make I hope it all makes sense. :) |
Any idea when this issue will be handled? Ugly, but it doesn't block development while still taking advantage of Spring Hatoas... |
+1 |
1 similar comment
+1 |
We're gonna do three things:
|
+1 |
+1 |
+1 |
3 similar comments
+1 |
+1 |
+1 |
I developed a framework to render links in spring hateoas projects. It also supports rendering links for user defined types. An explanation can be found in this stackoverflow answer |
Is there an end in sight for this bug? It's been open for almost 2 years and none of the provided solutions have worked in our situation. |
+1 |
1 similar comment
+1 |
Need to figure out a pared back version of this. The issue is against Spring Data JPA + Spring Data REST, so it's current incarnation requires hooking together lots of components. If there is a Spring HATEOAS-specific issue, need a much simpler case to illustrate. |
Existing ConversionService is fixed as a static inside BoundMethodParameter. This introduces ability to inject an alternative ConversionService. Related issues: #352
A simple case: I have controller method parameter with custom types that are annotated with annotations such as @PathVariable or @RequestParam. While Spring MVC is behaving correctly by using my custom A (simplified) code example: @Controller
@RequestMapping("/users/{userId}")
public class UserProfileController {
@GetMapping(produces = MediaType.TEXT_HTML_VALUE)
public ModelAndView showProfile(final @PathVariable("userId") String userId,
final @RequestParam(required = false) UriTemplate customVariable) {
final Map<String, Object> model = new HashMap<>();
final URI action = ControllerLinkBuilder.linkTo(ControllerLinkBuilder.methodOn(UserProfileController.class).updateProfile(userId, customVariable, null))
.toUri();
model.put("formAction", action);
return new ModelAndView("template", model);
}
@PostMapping(consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.TEXT_HTML_VALUE)
public ModelAndView updateProfile(final @PathVariable("userId") String userId,
final @RequestParam(required = false) UriTemplate customVariable,
final @Valid @ModelAttribute UserForm form) {
....
}
} Without my hack, creating the form action URI would result in a I am not using Spring Data / Spring Data REST. |
Spring HATEOAS at its core has a static conversion service setup to support the static factory methods. The related commit is a first swing at injecting an override. I wanted to discuss it with Oliver since many things are starting to come out as consequences of these static helpers. |
Just post a temporary Config Fix in Spring boot, with help from https://stackoverflow.com/questions/22240155/converter-from-pathvariable-domainobject-to-string-using-controllerlinkbuilde/22263269#22263269
|
@caoyuanqi While you're doing that reflection magic, you may find Spring Framework's ReflectionUtils and ReflectionTestUtils something of interest to make interacting with Java's Reflection API a little easier to use. |
I ran into this issue yesterday and managed to work it around this way.
I can also see that there has been PR (#618) out by @gregturn for some time. Is there a chance that it's going to get reviewed and merged anytime soon? |
Any updates on this? |
+1 |
1 similar comment
+1 |
@laszlocsontos's solution above still works well for 1.0.3 with the change:
I guess Thanks |
It seems not working with hateoas:0.24.0. But maybe it is my mistake. I have a converter like this: @Component
public class StringToJodaTimeConverter implements Converter<String, DateTime> {
@Override
public DateTime convert(@NotNull String source) {
return DateTime.parse(source, DateTimeFormat.forPattern("YYYY-MM-dd HH:mm:ss").withZoneUTC());
}
} And the method signature looks like this: public ResponseEntity getRequests(
@RequestParam(value = "to", required = false) DateTime upTo,
@AuthenticationPrincipal User current) { I am trying to convert the linkTo(methodOn(ServingVersionRequestsApi.class).getRequests(DateTime.now(UTC), null)).withRel("next") |
Issue not resolved in 1.0.4. @laszlocsontos solution above with @aisensiy modification is necessary still. |
Can someone please clarify what is the situation with this problem? since this solution does not even work anymore since there is no more |
I use the solution from @laszlocsontos with @aisensiy modification with spring HATEOAS 1.1.2. TL:DR; |
This is in place now. We look up the |
Currently the BoundMethodParameter class references a static, default instance of
ConversionService
. This means that should a user addConverter
s to theirApplicationContext
they will not be picked up and used. This should be changed such that aConversionService
specified in theApplicationContext
will be used, otherwise the default will be.The text was updated successfully, but these errors were encountered: