You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Having started used the HATEOAS Spring framework, I've found the ControllerLinkBuilderlinkTo and methodOn methods to be very useful to link resources to one another.
However, since some controller classes may use an Enum as a PathVariable, one may want to include those Enum's in links by using their Enumvalue using a custom Converter, and not by their name. The default Enum -> String Converter uses the Enum's name to do this conversion.
Unfortunately, because of this referenced line, the HATEOAS spring framework creates a new DefaultFormattingConversionService and doesn't include Converters that are created as Bean's within an ApplicationContext or via DefaultFormattingConversionService.addFormatters.
Example
Creating a simple GET mapping with the following path:
in the HATEOAS link. As opposed to using the Enum "value", be it an int or String, etc. because of Spring HATEOAS always creating a new DefaultFormattingConversionService.
Could we mix in Converter classes on the ApplicationContext to the list of converters HATEOAS uses for links or at least provide some way to add them to the ConversionService explicitly?
Thanks for reporting this. This is being worked on in the context of #618 (the original ticket being #118). Unsure how to resolve that as the static ControllerLinkBuilder limits our ability to pick up Spring MVC configuration.
Having started used the HATEOAS Spring framework, I've found the
ControllerLinkBuilder
linkTo and methodOn methods to be very useful to link resources to one another.However, since some controller classes may use an
Enum
as aPathVariable
, one may want to include thoseEnum
's in links by using theirEnum
value using a customConverter
, and not by their name. The default Enum -> StringConverter
uses theEnum
's name to do this conversion.Unfortunately, because of this referenced line, the HATEOAS spring framework creates a new
DefaultFormattingConversionService
and doesn't includeConverter
s that are created as Bean's within anApplicationContext
or viaDefaultFormattingConversionService.addFormatters
.Example
Creating a simple GET mapping with the following path:
And then creating a resource link to that path like this:
Will always give:
in the HATEOAS link. As opposed to using the Enum "value", be it an int or String, etc. because of Spring HATEOAS always creating a new
DefaultFormattingConversionService
.Could we mix in
Converter
classes on theApplicationContext
to the list of converters HATEOAS uses for links or at least provide some way to add them to theConversionService
explicitly?spring-hateoas/src/main/java/org/springframework/hateoas/mvc/AnnotatedParametersParameterAccessor.java
Line 133 in 05f687e
The text was updated successfully, but these errors were encountered: