EN
Java - Is it thread-safe to declare Jackson's ObjectMapper as a static field?
1 answers
8 points
I am confused about using Jackson's com.fasterxml.jackson.databind.ObjectMapper
class instance as static field in the class because of possible thread-safety issues.
I have found in information where thread-safety is confirmed (Using Jackson Object Mapper).
Is it true?
1 answer
7 points
Yes, it is true.
Even more, it is recommended to use com.fasterxml.jackson.databind.ObjectMapper
class instance as static field during entire lifetime of application when it is possible. The reasone why the mapper class is not static is giving user option to use different configurations per mapper instance.
From documentation:
Mapper instances are fully thread-safe provided that ALL configuration of the instance occurs before ANY read or write calls.
Sources:
0 commentsShow commentsAdd comment