what do you think about this pattern: ``` object J...
# codereview
c
what do you think about this pattern:
Copy code
object Jackson : ObjectMapper() {
     init {
         enable(SerializationFeature.INDENT_OUTPUT)
         ....
         }
}
t
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
yeah, I’m a bit on the fence if i need to inject dependencies like jackson, because its such a comodity.
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
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