I'm using Spring boot to expose an API.
For the method createTransaction
in TransactionController
,
@RestController
@RequestMapping(value = "/Transactions")
public class TransactionController{
@PostMapping("/create")
public ResponseEntity<Transaction> createTransaction(
@RequestParam Optional<String> name) {
// stuff
}
}
The API works perfectly, but I have the following warning :
Warning:(29, 27) 'Optional' used as type for parameter 'name'
When I add a SuppressWarnings
to avoid the compilator warning for this specefic method when I use Optional
as a parameter (since I'm aware of the risk)
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
The API return 404 not found
{
"timestamp": "2020-06-05T11:32:36.053+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/Transactions/create"
}
Any idea on what's the issue ?
I want to use Optional
parameter without getting warnings.