Hi I have a problem with serialization enum using ...
# spring
v
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
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
Ohhh, that might be that case. And is it possible to use set it up to use jackson?
j
I don't think it would make any sense because request parameters and actual body are different things
🙏 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
Also is there a Spring documentation that explains how it works in detail?
p
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