Hi,
I found a half-way solution for my case. I added AnnotationMethodHandlerExceptionResolver in the servlet.xml
Code:
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver">
<property name="messageConverters">
<list>
<ref bean="marshallingConverter" />
<ref bean="jsonConverter" />
</list>
</property>
</bean>
And my Controller code like below:
Code:
@Controller
public class SimpleController {
// other controller method omitted
@ExceptionHandler(IOException.class)
public @ResponseBody IOException handleIOException(IOException ex, HttpServletRequest request) {
return ex;
}
}
By doing so, I can get the exception with message in JSON
Code:
{"cause":null,"message":"my custom exception message","localizedMessage":"my custom exception message","stackTrace":[{"className":"sun.reflect.NativeMethodAccessorImpl","fileName":null,"lineNumber":-2,"methodName":"invoke0","nativeMethod":true},{"className":"sun.reflect.NativeMethodAccessorImpl","fileName":null,"lineNumber":-1,"methodName":"invoke","nativeMethod":false},
.....
< Long Long Stack Trace>
.....
]
Any idea to take out the 'stack trace' from the JSON ? Actually, I only interest to send BOLD text as JSON to the REST client.
I would like to log the stack trace in REST server log, but not sending the stack trace to the rest client (Its meaningless to REST Client)
Thanks for viewing and/or advises.