java - How do I correctly reuse Jackson ObjectMapper? -


i happy how objectmapper works , general use within application. understand best way implement objectmapper ensure re-used , i'm not creating unnecessary instances within application?

my thoughts can declare objectmapper in utils class follows:

public class utils {      public final static objectmapper mapper = new objectmapper();  } 

i reference various places need using code such as:

jsonsimple jsonsimple = utils.mapper.readvalue(jsonstring, jsonsimple.class); 

i came across other question (should declare jackson's objectmapper static field?) prompted approach. think maybe key difference want share objectmapper instance across many different classes, not within single class.

does approach sound appropriate or missing something?

thanks

it's fine use single instance per application provided don't call configuration methods after it's been made visible i.e. should initialization inside static block.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -