https://kotlinlang.org logo
Title
n

nkiesel

05/05/2022, 5:24 PM
(I know it's more a Jackson than a Kotlin question, but I hope someone might have an answer anyway). I have a line `val jackson: YAMLMapper = YAMLMapper.builder().addModule(KotlinModule()).build()`in my code to create a Jackson YAML mapper with Kotlin extensions. This tells me "Kotlin: 'constructor KotlinModule(Int = ..., Boolean = ..., Boolean = ..., Boolean = ..., SingletonSupport = ..., Boolean = ...)' is deprecated. Use KotlinModule.Builder instead of named constructor parameters". Does that really mean I should use `val jackson: YAMLMapper = YAMLMapper.builder().addModule(KotlinModule.Builder().build()).build()`instead? That's an awful amount of build...
e

ephemient

05/05/2022, 5:34 PM
use
kotlinModule { }
n

nkiesel

05/05/2022, 5:39 PM
and how do I get the YAML mapper into that?
m

Matthew Gast

05/05/2022, 5:40 PM
An alternative way is to use:
val jackson = ObjectMapper(YAMLFactory()).registerKotlinModule()
n

nkiesel

05/05/2022, 5:42 PM
that will result in an
ObjectMapper
and not a
YAMLMapper
but should be ok for me because I don't think I need any YAMLMapper-specific APIs.
m

Matthew Gast

05/05/2022, 5:43 PM
Yeah, in most cases you shouldn't
e

ephemient

05/05/2022, 5:44 PM
kotlinModule { ... }
replaces
KotlinModule.Builder(). ... .build()
, so you should see how to use that with
YAMLMapper.builder()
n

nkiesel

05/05/2022, 6:18 PM
right. So I have 2 options which seems equally good:
ObjectMapper(YAMLFactory()).registerKotlinModule()
and
YAMLMapper.builder().addModule(kotlinModule()).build()
. Thanks for your help!