This code is demonstrating a bug with using @JsonView and handling exceptions.
To see this bug in action run the test "JsonViewBugTest".
To repeat the bug
- Create a JsonView class (Views.class)
- Create a rest GET endpoint.
- Declaration should return an object.
- Body of method should throw a custom exception.
- Annotate the endpoint with @JsonView(Views.Public.class)
- Create an exception handler for the custom exception.
- It should handle the response with setting a status code.
- It also needs to set something in the body. (See MyObjExceptionHandler)
- Annotate a given rest endpoint with JsonView(Views.class)
That should be enough to repeat the bug.
It apepars that io.micronaut.jackson.databind.JacksonDatabindMapper was changed such that it now registeres the expected type. Unforunately the type that is being converted is not the expected type and is instead of type JsonError. So the ObjectMapper throws an exception.