You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I call a rest method with the @JSONVIEW annotation. The method throws an error. The error gets handled by my error handler and returns the appropriate response status and body.
Actual Behaviour
Instead of my handled error response being returned I get a 500 error instead. In the logs I see an exception is thrown saying that the the JsonError is incompatible with the expected return type.
09:07:08.770 [io-executor-thread-3] ERROR i.m.http.server.RouteExecutor - Unexpected error occurred: Error encoding object [Not Found] to JSON: Incompatible types: declared root type ([simple type, class test_email_validation.MyObj]) vs `io.micronaut.http.hateoas.JsonError`
io.micronaut.http.codec.CodecException: Error encoding object [Not Found] to JSON: Incompatible types: declared root type ([simple type, class test_email_validation.MyObj]) vs `io.micronaut.http.hateoas.JsonError`
at io.micronaut.json.codec.MapperMediaTypeCodec.encode(MapperMediaTypeCodec.java:268)
at io.micronaut.http.server.netty.jackson.JsonViewServerFilter.lambda$doFilter$1(JsonViewServerFilter.java:99)
at reactor.core.publisher.MonoCallable.call(MonoCallable.java:72)
at reactor.core.publisher.FluxSubscribeOnCallable$CallableSubscribeOnSubscription.run(FluxSubscribeOnCallable.java:227)
at io.micronaut.core.propagation.PropagatedContext.lambda$wrap$3(PropagatedContext.java:211)
at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:68)
at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:28)
at io.micronaut.core.propagation.PropagatedContext.lambda$wrap$4(PropagatedContext.java:228)
at io.micronaut.core.propagation.PropagatedContext.lambda$wrap$4(PropagatedContext.java:228)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Incompatible types: declared root type ([simple type, class test_email_validation.MyObj]) vs `io.micronaut.http.hateoas.JsonError`
at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77)
at com.fasterxml.jackson.databind.SerializerProvider.reportBadDefinition(SerializerProvider.java:1308)
at com.fasterxml.jackson.databind.SerializerProvider._reportIncompatibleRootType(SerializerProvider.java:1399)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:380)
at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1568)
at com.fasterxml.jackson.databind.ObjectWriter._writeValueAndClose(ObjectWriter.java:1273)
at com.fasterxml.jackson.databind.ObjectWriter.writeValueAsBytes(ObjectWriter.java:1163)
at io.micronaut.jackson.databind.JacksonDatabindMapper.writeValueAsBytes(JacksonDatabindMapper.java:209)
at io.micronaut.json.codec.MapperMediaTypeCodec.encode(MapperMediaTypeCodec.java:265)
... 12 common frames omitted
Steps To Reproduce
Create a GET rest endpoint
Annotate rest endpoint with JSON view and the appropriate view class
rest endpoint should declare a return type other than void.
Throw a custom exception
Create a ExceptionHandler for the custom exception
ExceptionHandler should generate a response with a body of type JsonError.
Startup the application, hit the endpoint that throws the custom exception. This should result in a 500 error because JsonError is not of the same type as the rest endpoint return type.
Expected Behavior
I call a rest method with the @JSONVIEW annotation. The method throws an error. The error gets handled by my error handler and returns the appropriate response status and body.
Actual Behaviour
Instead of my handled error response being returned I get a 500 error instead. In the logs I see an exception is thrown saying that the the JsonError is incompatible with the expected return type.
Steps To Reproduce
Environment Information
Example Application
https://github.com/kevind-wgu/micronaut-jsonview-bug
Version
4.1.2
The text was updated successfully, but these errors were encountered: