Home » Java » java – how override zalando problem object toString in controlAdvice-Exceptionshub

java – how override zalando problem object toString in controlAdvice-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

i’m use zalando with Spring boot for manage my controlAdvice
now my json response is

{
    "status": "404",
    "title": "title",
    "data": "null"
}

and i want to change it in

{"body":

{
    "status": "404",
    "title": "title",
    "data": "null"
}

}

my control Advice code :

@ExceptionHandler
    public ResponseEntity<Problem> activationException(ActivationException ex, NativeWebRequest request) {
        Problem problem = Problem.builder()
                .withStatus(Status.BAD_REQUEST)
                .withTitle(ex.getMessage())
                .with(DATA, null)
                .build();
        return create(ex, problem, request);
    }

How to&Answers: