All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fasterxml.jackson.jaxrs.cfg.ObjectWriterInjector Maven / Gradle / Ivy

Go to download

Ehcache is an open source, standards-based cache used to boost performance, offload the database and simplify scalability. Ehcache is robust, proven and full-featured and this has made it the most widely-used Java-based cache.

There is a newer version: 2.10.9.2
Show newest version
package com.fasterxml.jackson.jaxrs.cfg;

import java.util.concurrent.atomic.AtomicBoolean;

import com.fasterxml.jackson.databind.*;

/**
 * Based on ideas from [Issue#32], this class allows "overriding" of {@link ObjectWriter}
 * that JAX-RS Resource will use; usually this is done from a Servlet or JAX-RS filter
 * before execution reaches resource.
 * 
 * @since 2.3
 */
public class ObjectWriterInjector
{
   protected static final ThreadLocal _threadLocal = new ThreadLocal();

   /**
    * Simple marker used to optimize out {@link ThreadLocal} access in cases
    * where this feature is not being used
    */
   protected static final AtomicBoolean _hasBeenSet = new AtomicBoolean(false);

   private ObjectWriterInjector() { }
   
   public static void set(ObjectWriterModifier mod) {
       _hasBeenSet.set(true);
       _threadLocal.set(mod);
   }

   public static ObjectWriterModifier get() {
       return _hasBeenSet.get() ? _threadLocal.get() : null;
   }
   
   public static ObjectWriterModifier getAndClear() {
       ObjectWriterModifier mod = get();
       if (mod != null) {
           _threadLocal.remove();
       }
       return mod;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy