Skip to content

Commit

Permalink
Try builder first, then fallback to deprecated constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Sineaggi committed May 20, 2024
1 parent 9cdff7a commit 6f6cfd9
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ class KotlinObjectMapperFactory {
fun new(): ObjectMapper {
val mapper = JacksonJsonPayloadConverter.newDefaultObjectMapper()

// use deprecated constructor instead of builder to maintain compatibility with old jackson versions
@Suppress("deprecation")
val km = KotlinModule()
val km = try {
KotlinModule.Builder()
.build()
} catch (e: ClassNotFoundException) {
// use deprecated constructor as fallback
@Suppress("deprecation")
KotlinModule()
}
mapper.registerModule(km)
return mapper
}
Expand Down

0 comments on commit 6f6cfd9

Please sign in to comment.