Micronaut consumes and produces stopped working after upgrade to micronaut 4

151 views Asked by At

On micronaut version 3, it worked fine, while migrating to micronaut 4, stopped working

In a endpoint annotated with

 @Get("/{someId}/someAction", produces = ["application/some.v1+json"] )

When I call it (eg. postman) micronaut gives me an error on console

io.micronaut.http.codec.CodecException: Cannot encode value [[]]. No possible encoders found for media type: application/vnd.v1+json

here's a piece of my controller

@Validated
@Controller("/something")
class SomethingController(@Inject val service: SomeService) {

    @Secured(SecurityRule.IS_AUTHENTICATED)
    @Get("/{someId}/someAction", 
         produces = ["application/some.v1+json"], 
         consumes = ["application/some.v1+json"])
    fun getSomething(
            someId: UUID,
            principal: Principal
    ): List<SomeResource>  {
        principal as MyIdentity
        return service.findAll(someId, principal)
    }

My service has more endpoints, is there a way to write one codec that handle with all those customs produces and consumes?

1

There are 1 answers

0
João Cota On

By adding a codec on application yaml, I was able to fix my issue. I wondering if there is another way to fix that, since micronaut 3 supported that

https://docs.micronaut.io/latest/guide/index.html#consumesAnnotation