Ghostyjangle
JCHJava Community | Help. Code. Learn.
•Created by Ghostyjangle on 9/20/2024 in #java-help
[Spring] Should I have a custom Objectmapper as a static attribute in my service class?
Currently have an Objectmapper, from the JSON jackson serialization api, from my configuration class used in my Service class. Using lombok, realized the @AllArgsConstructor doesn't create a constructor for static attributes.
It makes sense to have it be static in the conventional sense, since it should be shared between service instances.
It is making it hard to do unit tests. As best practice, should I be having the objectmapper attribute in my service class be static or not?
I'm thinking I can forgo making it static since I'm getting a universal Objectmapper from the spring context anyway.
Would appreciate the help.
23 replies