I have a spring boot webapp in which I have defined REST APIs. I am using spring security for REST API security.
I have annotated my controller classes with RestController. I recently updated spring boot, mvc and security to the latest version.
I am now seeing that in my negative cases, before the update it was returning json error response, but now after the update, it is returning html error response.
Before the update, it was giving following error response-
{
"timestamp": "2018-05-21T18:22:37.105+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Error message.",
"path": "<API path>"
}
After the update, it is giving following response.
<!DOCTYPE html>
<html>
<head>
<title>Apache Tomcat/8.0.51 - Error report</title>
<style type="text/css">H1 {font-family:Tahoma,Arial,sansserif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}</style>
</head>
<body>
<h1>HTTP Status 500 - Error message.</h1>
<div class="line"></div>
<p>
<b>type</b> Status report
</p>
<p>
<b>message</b>
<u>Error message.</u>
</p>
<p>
<b>description</b>
<u>The server encountered an internal error that prevented it from fulfilling this request.</u>
</p>
<hr class="line">
<h3>Apache Tomcat/8.0.51</h3>
</body>
</html>
I did not had any ExceptionHandler in my Controller. It was coming as json error by default. I have jackson and jackson-mapper-asl in my libs.
I could not figure out if there is a default setting somewhere that needs to be changed to send errors as json.
I also tried to disable ErrorPageFilter but even after that I am getting HTML response.
Is there any way by which I can get json response rather than html?