Sometimes when we have our method to return a JSON is setup wrong, we get a 404 even though we are hitting the method. To be able to successfully return a JSON, the method needs to return ResponseEntity<String> as in the following method’s signature:
@RequestMapping(value = "/open-orders", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity<String> getOrdersJson() {
...
return new ResponseEntity<>(ordersJSONString, HttpStatus.OK);
}
As you can see in the example, we have a GET method that produces a JSON and it needs to return ResponseEntity.
Once the method is setup in this way, we wouldn’t get a 404 as long we are hitting the right URL.
0 Comments