Jackson Best Practices: Thread Safety

Jackson follows thread-safety rules typical for modern factory-based Java data format handlers (similar to what, say, Stax or JAXP implementations do). For example:

So... ?

Basically, following usage pattern is perfectly fine, regarding thread-safety:

class MyJsonProcessingClass
{
   protected final static ObjectMapper defaultMapper = new ObjectMapper();
   static { // if you need to change default configuration:
     defaultMapper.configure(SerializationConfig.Feature.USE_STATIC_TYPING, true); // faster this way, not default
   }

   public String doJson(MyData dataObject) throws IOException
   {
      return defaultMapper.writeValueAsString(dataObject);
   }
}


Back to JacksonDocumentation


CategoryJackson

JacksonBestPracticeThreadSafety (last edited 2010-10-11 22:15:27 by TatuSaloranta)

Copyright ©2009 FasterXML, LLC