Add jackson-kotlin-module in a Kotlin-based project when Jackson is present
See original GitHub issueAs asked on #152 and as a follow-up of #400, I create a dedicated issue for discussing a way to add jackson-kotlin-module
for Spring Boot + Kotlin + Jackson projects (mostly Web and Reactive Web projects) with a copy & paste of my #152 last comment.
I truly understand this is not an easy one, but even with documentation, projects using Boot + Kotlin + Jackson (vast majority of Kotlin projects) are broken out of the box for use cases as simple as writing a REST webservice. IMO even experienced developers will forget to add it 50% of the time because with start.spring.io, we have the habits of just generating a project, write classes, run and it works. So when I saw this issue I thought it would be interesting to discuss if it could be use to help for such use case (even if maybe it is not).
Having the capability to add a post-processor able to inspect transitive dependencies and add jackson-kotlin-module
dependency when jackson-databind
is found in transitive dependencies and when "language == 'kotlin'"
would be awesome, but as you said that’s not possible easily currently and that’s not what I had in mind.
My proposal is a more basic approach where we leverage the new feature discussed here to add for dependencies like “Web” and “Reactive Web” (maybe a few others like “Ratpack” or “Vaadin” if that makes sense) an additional jackson-kotlin-module
dependency if a condition like "language == 'kotlin'"
is fulfilled. This is not a perfect solution (duplication in the meta-data, will not cover all use cases if we focused on the most common dependencies requiring Jackson) but given the current set of constraints, I thought it could be a possible one.
Any thoughts?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
We’ve decided to add the dependency in Spring Boot’s json starter.
@bclozel Good point, adding
jackson-module-kotlin
(with exclusion ofkoltin-reflect
dependency) tospring-boot-starter-json
as described in https://github.com/spring-projects/spring-boot/issues/9803 would solve this issue on Springn Boot side, so that would be even better.