question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bad serialization of response when using @EnableWebMvc

See original GitHub issue

Whenever I introduce @EnableWebMvc on a configuration class, the response of a bad request is of type application/problem+json, as it should, but it has all the fields: stacktrace, parameters, etc etc. When I comment out the annotation, it serializes properly. is this a bug? it sounds to me like it’s not, but is it something that can be improved in the library so that it works in both scenarios?

With @EnableWebMvc

    "cause": null,
    "stackTrace": [
        {
            "methodName": "noHandlerFound",
            "fileName": "DispatcherServlet.java",
            "lineNumber": 1253,
            "className": "org.springframework.web.servlet.DispatcherServlet",
            "nativeMethod": false
        },
        {
            "methodName": "doDispatch",
            "fileName": "DispatcherServlet.java",
            "lineNumber": 1017,
            "className": "org.springframework.web.servlet.DispatcherServlet",
            "nativeMethod": false
        },
        {
            "methodName": "doService",
            "fileName": "DispatcherServlet.java",
            "lineNumber": 942,
            "className": "org.springframework.web.servlet.DispatcherServlet",
            "nativeMethod": false
        },
        {
            "methodName": "processRequest",
            "fileName": "FrameworkServlet.java",
            "lineNumber": 1005,
            "className": "org.springframework.web.servlet.FrameworkServlet",
            "nativeMethod": false
        },
        {
            "methodName": "doGet",
            "fileName": "FrameworkServlet.java",
            "lineNumber": 897,
            "className": "org.springframework.web.servlet.FrameworkServlet",
            "nativeMethod": false
        },
        {
            "methodName": "service",
            "fileName": "HttpServlet.java",
            "lineNumber": 645,
            "className": "javax.servlet.http.HttpServlet",
            "nativeMethod": false
        },
        {
            "methodName": "service",
            "fileName": "FrameworkServlet.java",
            "lineNumber": 882,
            "className": "org.springframework.web.servlet.FrameworkServlet",
            "nativeMethod": false
        },
        {
            "methodName": "service",
            "fileName": "HttpServlet.java",
            "lineNumber": 750,
            "className": "javax.servlet.http.HttpServlet",
            "nativeMethod": false
        },
        {
            "methodName": "handle",
            "fileName": "ServletHolder.java",
            "lineNumber": 873,
            "className": "org.eclipse.jetty.servlet.ServletHolder",
            "nativeMethod": false
        },
        {
            "methodName": "doFilter",
            "fileName": "ServletHandler.java",
            "lineNumber": 1623,
            "className": "org.eclipse.jetty.servlet.ServletHandler$CachedChain",
            "nativeMethod": false
        },
        {
            "methodName": "doFilter",
            "fileName": "WebSocketUpgradeFilter.java",
            "lineNumber": 214,
            "className": "org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter",
            "nativeMethod": false
        },
        {
            "methodName": "doFilter",
            "fileName": "ServletHandler.java",
            "lineNumber": 1610,
            "className": "org.eclipse.jetty.servlet.ServletHandler$CachedChain",
            "nativeMethod": false
        },
        {
            "methodName": "doFilterInternal",
            "fileName": "RequestContextFilter.java",
            "lineNumber": 99,
            "className": "org.springframework.web.filter.RequestContextFilter",
            "nativeMethod": false
        },
        {
            "methodName": "doFilter",
            "fileName": "OncePerRequestFilter.java",
            "lineNumber": 107,
            "className": "org.springframework.web.filter.OncePerRequestFilter",
            "nativeMethod": false
        },
        {
            "methodName": "doFilter",
            "fileName": "ServletHandler.java",
            "lineNumber": 1610,
            "className": "org.eclipse.jetty.servlet.ServletHandler$CachedChain",
            "nativeMethod": false
        },
        {
            "methodName": "doFilterInternal",
            "fileName": "FormContentFilter.java",
            "lineNumber": 92,
            "className": "org.springframework.web.filter.FormContentFilter",
            "nativeMethod": false
        },
        {
            "methodName": "doFilter",
            "fileName": "OncePerRequestFilter.java",
            "lineNumber": 107,
            "className": "org.springframework.web.filter.OncePerRequestFilter",
            "nativeMethod": false
        },
        {
            "methodName": "doFilter",
            "fileName": "ServletHandler.java",
            "lineNumber": 1610,
            "className": "org.eclipse.jetty.servlet.ServletHandler$CachedChain",
            "nativeMethod": false
        },
        {
            "methodName": "doFilterInternal",
            "fileName": "HiddenHttpMethodFilter.java",
            "lineNumber": 93,
            "className": "org.springframework.web.filter.HiddenHttpMethodFilter",
            "nativeMethod": false
        },
        {
            "methodName": "doFilter",
            "fileName": "OncePerRequestFilter.java",
            "lineNumber": 107,
            "className": "org.springframework.web.filter.OncePerRequestFilter",
            "nativeMethod": false
        },
        {
            "methodName": "doFilter",
            "fileName": "ServletHandler.java",
            "lineNumber": 1610,
            "className": "org.eclipse.jetty.servlet.ServletHandler$CachedChain",
            "nativeMethod": false
        },
        {
            "methodName": "doFilterInternal",
            "fileName": "CharacterEncodingFilter.java",
            "lineNumber": 200,
            "className": "org.springframework.web.filter.CharacterEncodingFilter",
            "nativeMethod": false
        },
        {
            "methodName": "doFilter",
            "fileName": "OncePerRequestFilter.java",
            "lineNumber": 107,
            "className": "org.springframework.web.filter.OncePerRequestFilter",
            "nativeMethod": false
        },
        {
            "methodName": "doFilter",
            "fileName": "ServletHandler.java",
            "lineNumber": 1610,
            "className": "org.eclipse.jetty.servlet.ServletHandler$CachedChain",
            "nativeMethod": false
        },
        {
            "methodName": "doHandle",
            "fileName": "ServletHandler.java",
            "lineNumber": 540,
            "className": "org.eclipse.jetty.servlet.ServletHandler",
            "nativeMethod": false
        },
        {
            "methodName": "handle",
            "fileName": "ScopedHandler.java",
            "lineNumber": 146,
            "className": "org.eclipse.jetty.server.handler.ScopedHandler",
            "nativeMethod": false
        },
        {
            "methodName": "handle",
            "fileName": "SecurityHandler.java",
            "lineNumber": 548,
            "className": "org.eclipse.jetty.security.SecurityHandler",
            "nativeMethod": false
        },
        {
            "methodName": "handle",
            "fileName": "HandlerWrapper.java",
            "lineNumber": 132,
            "className": "org.eclipse.jetty.server.handler.HandlerWrapper",
            "nativeMethod": false
        },
        {
            "methodName": "nextHandle",
            "fileName": "ScopedHandler.java",
            "lineNumber": 257,
            "className": "org.eclipse.jetty.server.handler.ScopedHandler",
            "nativeMethod": false
        },
        {
            "methodName": "doHandle",
            "fileName": "SessionHandler.java",
            "lineNumber": 1700,
            "className": "org.eclipse.jetty.server.session.SessionHandler",
            "nativeMethod": false
        },
        {
            "methodName": "nextHandle",
            "fileName": "ScopedHandler.java",
            "lineNumber": 255,
            "className": "org.eclipse.jetty.server.handler.ScopedHandler",
            "nativeMethod": false
        },
        {
            "methodName": "doHandle",
            "fileName": "ContextHandler.java",
            "lineNumber": 1345,
            "className": "org.eclipse.jetty.server.handler.ContextHandler",
            "nativeMethod": false
        },
        {
            "methodName": "nextScope",
            "fileName": "ScopedHandler.java",
            "lineNumber": 203,
            "className": "org.eclipse.jetty.server.handler.ScopedHandler",
            "nativeMethod": false
        },
        {
            "methodName": "doScope",
            "fileName": "ServletHandler.java",
            "lineNumber": 480,
            "className": "org.eclipse.jetty.servlet.ServletHandler",
            "nativeMethod": false
        },
        {
            "methodName": "doScope",
            "fileName": "SessionHandler.java",
            "lineNumber": 1667,
            "className": "org.eclipse.jetty.server.session.SessionHandler",
            "nativeMethod": false
        },
        {
            "methodName": "nextScope",
            "fileName": "ScopedHandler.java",
            "lineNumber": 201,
            "className": "org.eclipse.jetty.server.handler.ScopedHandler",
            "nativeMethod": false
        },
        {
            "methodName": "doScope",
            "fileName": "ContextHandler.java",
            "lineNumber": 1247,
            "className": "org.eclipse.jetty.server.handler.ContextHandler",
            "nativeMethod": false
        },
        {
            "methodName": "handle",
            "fileName": "ScopedHandler.java",
            "lineNumber": 144,
            "className": "org.eclipse.jetty.server.handler.ScopedHandler",
            "nativeMethod": false
        },
        {
            "methodName": "handle",
            "fileName": "HandlerWrapper.java",
            "lineNumber": 132,
            "className": "org.eclipse.jetty.server.handler.HandlerWrapper",
            "nativeMethod": false
        },
        {
            "methodName": "handle",
            "fileName": "Server.java",
            "lineNumber": 505,
            "className": "org.eclipse.jetty.server.Server",
            "nativeMethod": false
        },
        {
            "methodName": "handle",
            "fileName": "HttpChannel.java",
            "lineNumber": 370,
            "className": "org.eclipse.jetty.server.HttpChannel",
            "nativeMethod": false
        },
        {
            "methodName": "onFillable",
            "fileName": "HttpConnection.java",
            "lineNumber": 267,
            "className": "org.eclipse.jetty.server.HttpConnection",
            "nativeMethod": false
        },
        {
            "methodName": "succeeded",
            "fileName": "AbstractConnection.java",
            "lineNumber": 305,
            "className": "org.eclipse.jetty.io.AbstractConnection$ReadCallback",
            "nativeMethod": false
        },
        {
            "methodName": "fillable",
            "fileName": "FillInterest.java",
            "lineNumber": 103,
            "className": "org.eclipse.jetty.io.FillInterest",
            "nativeMethod": false
        },
        {
            "methodName": "run",
            "fileName": "ChannelEndPoint.java",
            "lineNumber": 117,
            "className": "org.eclipse.jetty.io.ChannelEndPoint$2",
            "nativeMethod": false
        },
        {
            "methodName": "runTask",
            "fileName": "EatWhatYouKill.java",
            "lineNumber": 333,
            "className": "org.eclipse.jetty.util.thread.strategy.EatWhatYouKill",
            "nativeMethod": false
        },
        {
            "methodName": "doProduce",
            "fileName": "EatWhatYouKill.java",
            "lineNumber": 310,
            "className": "org.eclipse.jetty.util.thread.strategy.EatWhatYouKill",
            "nativeMethod": false
        },
        {
            "methodName": "tryProduce",
            "fileName": "EatWhatYouKill.java",
            "lineNumber": 168,
            "className": "org.eclipse.jetty.util.thread.strategy.EatWhatYouKill",
            "nativeMethod": false
        },
        {
            "methodName": "run",
            "fileName": "EatWhatYouKill.java",
            "lineNumber": 126,
            "className": "org.eclipse.jetty.util.thread.strategy.EatWhatYouKill",
            "nativeMethod": false
        },
        {
            "methodName": "run",
            "fileName": "ReservedThreadExecutor.java",
            "lineNumber": 366,
            "className": "org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread",
            "nativeMethod": false
        },
        {
            "methodName": "runJob",
            "fileName": "QueuedThreadPool.java",
            "lineNumber": 698,
            "className": "org.eclipse.jetty.util.thread.QueuedThreadPool",
            "nativeMethod": false
        },
        {
            "methodName": "run",
            "fileName": "QueuedThreadPool.java",
            "lineNumber": 804,
            "className": "org.eclipse.jetty.util.thread.QueuedThreadPool$Runner",
            "nativeMethod": false
        },
        {
            "methodName": "run",
            "fileName": "Thread.java",
            "lineNumber": 748,
            "className": "java.lang.Thread",
            "nativeMethod": false
        }
    ],
    "type": "about:blank",
    "title": "Not Found",
    "status": "NOT_FOUND",
    "detail": "No handler found for GET /genericd",
    "instance": null,
    "parameters": {},
    "message": "Not Found: No handler found for GET /genericd",
    "localizedMessage": "Not Found: No handler found for GET /genericd",
    "suppressed": []
}

Without @EnableWebMvc

{
    "title": "Not Found",
    "status": 404,
    "detail": "No handler found for GET /genericd"
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
whiskeysierracommented, Aug 5, 2019

If it’s a separate artifact/module that users can pick and choose, then sure, why not?

0reactions
IncPlusPluscommented, Mar 22, 2021

Leaving this here as a note for people who might run into this issue. The improper serialization of responses will likely also occur in tests that use the @WebMvcTest annotation. The solution that worked for me was to add @Import(ProblemJacksonAutoConfiguration.class) to my test classes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

EnableWebMvc disables/ignores spring.jackson.serialization ...
LocalDate is still being serialized as an array of integers. I am not using @EnableWebMvc anywhere. What am I doing wrong?
Read more >
Spring MVC, JSON, wrong serialization of string fields, that are ...
I see two possible solution: Use explicit convertation to JSON, like this: @Controller public class MyController { @Autowired ObjectMapper ...
Read more >
Spring Boot, @EnableWebMvc And Common Use-Cases
What happens when you add the annotation is that spring boot autoconfiguration is disabled. The bad part (that wasted me a few hours)...
Read more >
Web on Servlet Stack - Spring
You can use the @ResponseBody annotation on a method to have the return serialized to the response body through an HttpMessageConverter.
Read more >
Spring Boot and Jackson, JSR310 in response body-Springboot
Accepted answer. If you use @EnableWebMvc that would explain your symptoms So the rule thumb is: do not use @EnableWebMvc with Spring Boot,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found