Just see the code snippet of SpringMVC-3.2.x
controller action method. Its quite easy to generate JSON
but unable to add addtional custom header only f
You can add headers to the ResponseEntity builder. I think it is cleaner this way.
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
// ...
@GetMapping("/my/endpoint")
public ResponseEntity myEndpointMethod() {
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_TYPE, "application/json; charset=UTF-8");
return ResponseEntity.ok()
.headers(headers)
.body(data);
}