'Best Practice to transform request headers before passing it to rest contoller
I am working on a Spring Boot project with Java 11.
I have a rest controller that has a GET endpoint. The controller method takes account number as one of its arguments.
Account Number comes in as a request header.
Account number comes in as a 16 digit number. I have to use this account number to make another API call. However, this API expects account number to be in 20 digit format and hence I need to append 4 leading zeros every time.
Is there a best practice to do this transformation? I am thinking of creating a custom annotation and put it besides @RequestBody in the method argument.
For example -
public void getSampleData(@RequestBody @transform accountNumber) {…}
Solution 1:[1]
How about String.format("%020d", accountNumber)?
Best practice is to avoid problems, instead of trying to solve home-made problems.
Therefore I'd use an identical number-format on both sides; for the sake of simplicity.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Martin Zeitler |
