最佳答案
I am happy with how the ObjectMapper works and general use within my application. What I would like to understand is the best way to implement the ObjectMapper to ensure it is re-used and I'm not creating unnecessary instances within my application?
My thoughts are that I can declare the ObjectMapper in a Utils class as follows:
public class Utils {
public final static ObjectMapper mapper = new ObjectMapper();
}
I could then reference this from the various places I need to using code such as:
JsonSimple jsonSimple = Utils.mapper.readValue(jsonString, JsonSimple.class);
I came across this other question (Should I declare Jackson's ObjectMapper as a static field?) that prompted my approach. I think maybe the key difference is that I want to share my ObjectMapper instance across many different classes, not just within a single class.
Does this approach sound appropriate or am I missing something?
Thanks