Skip to content

I get two body after serialize exception #24633

Closed
@darkgirl

Description

@darkgirl

Hi,
I had custom my own exception controller like this

@ControllerAdvice
public class DefaultExceptionHandler {

	private static final Logger LOGGER = LoggerFactory.getLogger(DefaultExceptionHandler.class); 

	@ExceptionHandler(RuntimeException.class)
	@ResponseBody
	public ResponseData exceptionHandler(Exception exception,
			HttpServletRequest request,
			HttpServletResponse response) {
		
		
		ResponseData data = new ResponseData();
		data.setCode(-1);
		data.setSuccess(false);
		
		if (exception instanceof CustomizeRuntimeException) {
			var customException = (CustomizeRuntimeException)exception;
			data.setMessage(customException.getMessage());
		}
		else if (exception instanceof HttpRequestMethodNotSupportedException) {
			data.setMessage(exception.getMessage());
		}
		else {
			data.setMessage(exception.getMessage());
			exception.printStackTrace();
		}
		
		return data;
	}
}

and when there is a json serialize exception, I found I get two body from response.

{
    "message": "get session list successfully",
    "success": true,
    "code": 0,
    "result": {
        "id": "FCC0BF0A376C7BE89FAE26CEC9B6B77E",
        "creationTime": 1609640049356,
    }
}{
    "message": "Type definition error: [simple type, class java.util.logging.ErrorManager]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class java.util.logging.ErrorManager and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: com.mozzie.background.model.ResponseData[\"result\"]->org.apache.catalina.session.StandardSessionFacade[\"servletContext\"]->org.apache.catalina.core.ApplicationContextFacade[\"classLoader\"]->org.springframework.boot.web.embedded.tomcat.TomcatEmbeddedWebappClassLoader[\"resources\"]->org.apache.catalina.webresources.StandardRoot[\"context\"]->org.springframework.boot.web.embedded.tomcat.TomcatEmbeddedContext[\"logger\"]->org.apache.juli.logging.DirectJDKLog[\"logger\"]->java.util.logging.Logger[\"parent\"]->java.util.logging.Logger[\"parent\"]->java.util.logging.Logger[\"parent\"]->java.util.logging.Logger[\"parent\"]->java.util.logging.LogManager$RootLogger[\"handlers\"]->org.slf4j.bridge.SLF4JBridgeHandler[0]->org.slf4j.bridge.SLF4JBridgeHandler[\"errorManager\"])",
    "success": false,
    "code": -1,
    "result": null
}

Why is this so? and how to make it only response once before I solve the serialize exception?

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions