I have a SQL database where primary keys are UUIDs, but the canonical string representation of a UUID is very long, and I would like to use a shortened version (Base58) in my URLs. Spring Data's DomainClassConverter
will convert MVC request parameters or path variables into domain objects, but I want to be able to modify the resolved ID before it's passed to the repository.
The default SpringDataWebConfiguration
creates a DomainClassConverter
using a FormattingConversionService
supplied by the context, which presumably is not safe to arbitrarily mangle. Adding an annotation to the method parameters would potentially disambiguate the interpretation, but this would both have to be replicated all over the place and not work with external controllers such as Spring Data REST. The behavior of delegating the (String parameter
->ID) conversion to the conversion service is hard-wired in a private inner class, so I can't modify it there.
Is there any non-invasive way to intercept the parameter and transform it before it's passed to the RepositoryInvoker
?
easiest is if you create your own Formatter
like:
then register it in your application context:
@EnableSpringDataWebSupport
is used to bring a lot of beans into the context, see its javadoc - it's very informativebest