really depends on the project. I typically don't like using the kotlin object (language impl of singleton pattern). I'd rather let my DI system manage instances and lifecycle/scoping. However that can be over kill in simple cases. so I suppose the more important thing to me is that dependencies are still injected and consumers that need your Jackson instance depend on the
ObjectMapper
not on the Jackson object
c
christophsturm
08/29/2018, 6:33 PM
yeah, I’m a bit on the fence if i need to inject dependencies like jackson, because its such a comodity.
christophsturm
08/29/2018, 6:34 PM
basically i was going to inject it, but then a coworker suggested to make it a kotlin singleton, so i thought i post it here.
k
kingsley
08/31/2018, 3:08 PM
There’s also the option of having a:
Copy code
val Jackson = ObjectMapper().apply {
enable(SerializationFeature.INDENT_OUTPUT)
...
}
This avoids creating a totally new subclass of object mapper