Categories
Mastering Development

Add (custom) decoder to WebMVC endpoint

I have a WebMVC endpoint:

@RequestMapping(path = "/execution/{id}", method = RequestMethod.POST)
public ResponseEntity<...> execute(@PathVariable String id) {
   ...
}

Here, the provided id should be decoded first. Is it possible to define an annotation which does this "in the background"; that is, prior to calling the endpoint? Something in the lines of:

@RequestMapping(path = "/execution/{id}", method = RequestMethod.POST)
public ResponseEntity<...> execute(@PathVariable @DecodedIdentifier String id) {
   ...
}

Note the @DecodedIdentifier annotation. I know it does not exists, but it hopefully explains my intent. I know this is possible with Jersey’s JAX-RS implementation, but what about Spring’s WebMVC?

Here, I am using base64 decoding, but I wondering if I could inject a custom decoder as well.

Leave a Reply

Your email address will not be published. Required fields are marked *