in Education by
When I send unsupported JSON request I receive stack trace from Jackson that it doesn't have this property. On the @JsonIgnoreProperties(ignoreUnknown = true) I just got a response without necessary obtaining as expected. But how can I return for example 400 or another response code without stack trace? org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "dave" (Class com.atlassian.troubleshooting.jfr.domain.JfrSettings), not marked as ignorable at [Source: org.apache.catalina.connector.CoyoteInputStream@8aaf377; line: 1, column: 14] (through reference chain: com.atlassian.troubleshooting.jfr.domain.JfrSettings["dave"]) at org.codehaus.jackson.map.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:53) at org.codehaus.jackson.map.deser.StdDeserializationContext.unknownFieldException(StdDeserializationContext.java:267) JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
For me HttpMessageNotReadableException is thrown and UnrecognizedPropertyException is the nested exception. you can use SimpleMappingExceptionResolver and configure it like: @Configuration public class CustomConfiguration implements WebMvcConfigurer { @Bean public SimpleMappingExceptionResolver simpleMappingExceptionResolver(){ var mappings = new Properties(); mappings.setProperty("HttpMessageNotReadableException", "errorpage"); var statusCode = new Properties(); statusCode.setProperty("errorpage", String.valueOf(HttpServletResponse.SC_BAD_REQUEST)); var exeptionResolver = new SimpleMappingExceptionResolver(); exeptionResolver.setStatusCodes(statusCode); exeptionResolver.setExceptionMappings(mappings); return exeptionResolver; } @Override public void configureHandlerExceptionResolvers( List resolvers) { resolvers.add(simpleMappingExceptionResolver()); } } or use @ControllerAdvice like: @ControllerAdvice public class ControllerAdvisor { @ExceptionHandler(HttpMessageNotReadableException.class) public ResponseEntity handleCityNotFoundException( HttpMessageNotReadableException ex, WebRequest request) { // do stuff with ex and request return new ResponseEntity<>("body", HttpStatus.BAD_REQUEST); } } also as I said in the beginning the exception is HttpMessageNotReadableException and UnrecognizedPropertyException is just nested inside HttpMessageNotReadableException. If you use UnrecognizedPropertyException in above codes it won't work.

Related questions

0 votes
    How to get ASP.NET Web API to return JSON instead of XML using Chrome?...
asked Jan 11, 2021 in Technology by JackTerrance
0 votes
    I know there's no standard C function to do this. I was wondering what are the techniques to to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    Pulling my hair out here. All was working fine, and then out of the blue, I started to get some ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    Which of these methods is used to print stack trace? (a) obtainStackTrace() (b) printStackTrace() (c) ... Exception Handling of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    Which of these methods is used to print stack trace? (a) obtainStackTrace() (b) printStackTrace() (c ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    What HTTP Status Code 400 states in RESTful?...
asked Nov 7, 2020 in Technology by JackTerrance
0 votes
    _________ involves predicting a response with meaningful magnitude, such as quantity sold, stock price, or return on ... R Programming Select the correct answer from above options...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    Can we use JSON instead of YAML while developing docker-compose file in Docker?...
asked Jun 21, 2021 in Technology by JackTerrance
0 votes
    The following code from Bacon.js will push the data object returned from the AJAX request into the console. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 10, 2022 in Education by JackTerrance
0 votes
    I have a function foo which makes an asynchronous request. How can I return the response/result from foo? I am trying to ... (response) { result = response; // return response; //...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I have a function foo which makes an asynchronous request. How can I return the response/result from foo? I am trying to ... (response) { result = response; // return response; //...
asked Apr 14, 2022 in Education by JackTerrance
0 votes
    I have written tests with Selenium2/WebDriver and want to test if HTTP Request returns an HTTP 403 Forbidden. ... Selenium WebDriver? Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I'm traying to make some tests for an api here is the code: tests.py class APITest(APITestCase): ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    Given an integer typedef: typedef unsigned int TYPE; or typedef unsigned long TYPE; I have the following code to reverse ... TYPE bits= (TYPE)max_bit; while (bits = 1, bit_setter...
asked Mar 27, 2022 in Education by JackTerrance
0 votes
    Select the correct answer from above options...
asked Nov 16, 2021 in Education by JackTerrance
...