https://kotlinlang.org logo
Title
v

Václav Škorpil

06/21/2022, 12:01 PM
Hi I have a problem with serialization enum using kotlin, spring, jackson. I made a stack overflow question so i wont copy paste it, maybe someone of you will know how to solve it. https://stackoverflow.com/questions/72700370/spring-boot-serialize-kotlin-enum-by-custom-property.
👀 1
j

Jukka Siivonen

06/21/2022, 12:12 PM
Probably not Kotlin related but I think RequestParam does not use Jackson but Spring converters instead. If you use RequestBody then Jackson is used
1
v

Václav Škorpil

06/21/2022, 12:14 PM
Ohhh, that might be that case. And is it possible to use set it up to use jackson?
j

Jukka Siivonen

06/21/2022, 12:16 PM
I don't think it would make any sense because request parameters and actual body are different things
:thank-you: 1
🆗 1
So if you want this enum to work as a standalone req parameter and also inside body object you need Jackson configuration/annotation and custom Spring converter
1
v

Václav Škorpil

06/21/2022, 12:22 PM
Also is there a Spring documentation that explains how it works in detail?
p

pi0id

06/21/2022, 1:14 PM
For a regular conversion, Spring is able to initialize your param without any helping converter. In your case, a custom conversion is needed from
name
to
NAME
and from
registrationNumber
to
REGISTRATION_NUMBER
. So, create a class annotated with
@Component
that implements Converter interface. You just have to implement the required method
convert
from source object to target. Also, remove the
@RequestParam
annotation from the endpoint.
1