Kotlin Micronaut ConversionErrorException on desserialization, makes harder to validate treat error responses

37 Views Asked by At

I receive a request that contains an Enum, I want to validate this Enum using custom annotations from Micronaut Validation with Jakarta.

But the problem is: before I can validate my DTO data class who receive the request, Micronaut throws ConversionErrorException, probably because the way kotlin and data classes works, trying to construct with a non existent value to enum causing a conversion error due the null value.

So, the question is: there is a way to validate with Jakarta before? I want to return to the client a message from jakarta, returning the values that we accept, but with this exception I only can return a too generic response, like, "invalid data or null value provided)

Receive as String and after get valueOf() to get respective enum value is a good idea?

I tried to create custom annotations for validation in many ways, but the problem isn't that, is the null value before validation

0

There are 0 best solutions below