Class DeserializerStringCache

  • All Implemented Interfaces:
    java.util.function.Function<java.lang.String,​java.lang.String>

    public class DeserializerStringCache
    extends java.lang.Object
    implements java.util.function.Function<java.lang.String,​java.lang.String>
    A non-locking alternative to String.intern() and StringCache that works with Jackson's DeserializationContext. Definitely NOT thread-safe, intended to avoid the costs associated with thread synchronization and short-lived heap allocations (e.g., Strings)
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String apply​(com.fasterxml.jackson.core.JsonParser jp)
      returns a String read from the JsonParser argument's current position.
      java.lang.String apply​(com.fasterxml.jackson.core.JsonParser jp, DeserializerStringCache.CacheScope cacheScope)  
      java.lang.String apply​(com.fasterxml.jackson.core.JsonParser jp, DeserializerStringCache.CacheScope cacheScope, java.util.function.Supplier<java.lang.String> source)
      returns a String read from the JsonParser argument's current position.
      java.lang.String apply​(com.netflix.discovery.util.DeserializerStringCache.CharBuffer charValue)
      returns a String that may be interned at app-scope to reduce heap consumption
      java.lang.String apply​(com.netflix.discovery.util.DeserializerStringCache.CharBuffer charValue, DeserializerStringCache.CacheScope cacheScope)
      returns a object of type T that may be interned at the specified scope to reduce heap consumption
      java.lang.String apply​(java.lang.String stringValue)
      returns a String that may be interned at the app-scope to reduce heap consumption
      java.lang.String apply​(java.lang.String stringValue, DeserializerStringCache.CacheScope cacheScope)
      returns a String that may be interned at the given scope to reduce heap consumption
      static void clear​(com.fasterxml.jackson.databind.DeserializationContext context)
      clears app-scoped cache entries from the specified DeserializationContext
      static void clear​(com.fasterxml.jackson.databind.DeserializationContext context, DeserializerStringCache.CacheScope scope)
      clears cache entries in the given scope from the specified DeserializationContext.
      static void clear​(com.fasterxml.jackson.databind.ObjectReader reader)
      clears app-scoped cache entries from the specified ObjectReader
      static void clear​(com.fasterxml.jackson.databind.ObjectReader reader, DeserializerStringCache.CacheScope scope)
      clears cache entries in the given scope from the specified ObjectReader.
      static DeserializerStringCache from​(com.fasterxml.jackson.databind.DeserializationContext context)
      extracts a DeserializerStringCache from the DeserializationContext
      static com.fasterxml.jackson.databind.ObjectReader init​(com.fasterxml.jackson.databind.ObjectReader reader)
      adds a new DeserializerStringCache to the passed-in ObjectReader
      static com.fasterxml.jackson.databind.ObjectReader init​(com.fasterxml.jackson.databind.ObjectReader reader, com.fasterxml.jackson.databind.DeserializationContext context)
      adds an existing DeserializerStringCache from the DeserializationContext to an ObjectReader
      com.fasterxml.jackson.databind.ObjectReader initReader​(com.fasterxml.jackson.databind.ObjectReader reader)  
      int size()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.function.Function

        andThen, compose
    • Method Detail

      • init

        public static com.fasterxml.jackson.databind.ObjectReader init​(com.fasterxml.jackson.databind.ObjectReader reader)
        adds a new DeserializerStringCache to the passed-in ObjectReader
        Parameters:
        reader -
        Returns:
        a wrapped ObjectReader with the string cache attribute
      • init

        public static com.fasterxml.jackson.databind.ObjectReader init​(com.fasterxml.jackson.databind.ObjectReader reader,
                                                                       com.fasterxml.jackson.databind.DeserializationContext context)
        adds an existing DeserializerStringCache from the DeserializationContext to an ObjectReader
        Parameters:
        reader - a new ObjectReader
        context - an existing DeserializationContext containing a DeserializerStringCache
        Returns:
        a wrapped ObjectReader with the string cache attribute
      • from

        public static DeserializerStringCache from​(com.fasterxml.jackson.databind.DeserializationContext context)
        extracts a DeserializerStringCache from the DeserializationContext
        Parameters:
        context - an existing DeserializationContext containing a DeserializerStringCache
        Returns:
        a wrapped ObjectReader with the string cache attribute
      • clear

        public static void clear​(com.fasterxml.jackson.databind.ObjectReader reader)
        clears app-scoped cache entries from the specified ObjectReader
        Parameters:
        reader -
      • clear

        public static void clear​(com.fasterxml.jackson.databind.ObjectReader reader,
                                 DeserializerStringCache.CacheScope scope)
        clears cache entries in the given scope from the specified ObjectReader. Always clears app-scoped entries.
        Parameters:
        reader -
        scope -
      • clear

        public static void clear​(com.fasterxml.jackson.databind.DeserializationContext context)
        clears app-scoped cache entries from the specified DeserializationContext
        Parameters:
        context -
      • clear

        public static void clear​(com.fasterxml.jackson.databind.DeserializationContext context,
                                 DeserializerStringCache.CacheScope scope)
        clears cache entries in the given scope from the specified DeserializationContext. Always clears app-scoped entries.
        Parameters:
        context -
        scope -
      • initReader

        public com.fasterxml.jackson.databind.ObjectReader initReader​(com.fasterxml.jackson.databind.ObjectReader reader)
      • apply

        public java.lang.String apply​(com.fasterxml.jackson.core.JsonParser jp)
                               throws java.io.IOException
        returns a String read from the JsonParser argument's current position. The returned value may be interned at the app scope to reduce heap consumption
        Parameters:
        jp -
        Returns:
        a possibly interned String
        Throws:
        java.io.IOException
      • apply

        public java.lang.String apply​(com.fasterxml.jackson.core.JsonParser jp,
                                      DeserializerStringCache.CacheScope cacheScope)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • apply

        public java.lang.String apply​(com.fasterxml.jackson.core.JsonParser jp,
                                      DeserializerStringCache.CacheScope cacheScope,
                                      java.util.function.Supplier<java.lang.String> source)
                               throws java.io.IOException
        returns a String read from the JsonParser argument's current position. The returned value may be interned at the given cacheScope to reduce heap consumption
        Parameters:
        jp -
        cacheScope -
        Returns:
        a possibly interned String
        Throws:
        java.io.IOException
      • apply

        public java.lang.String apply​(com.netflix.discovery.util.DeserializerStringCache.CharBuffer charValue)
        returns a String that may be interned at app-scope to reduce heap consumption
        Parameters:
        charValue -
        Returns:
        a possibly interned String
      • apply

        public java.lang.String apply​(com.netflix.discovery.util.DeserializerStringCache.CharBuffer charValue,
                                      DeserializerStringCache.CacheScope cacheScope)
        returns a object of type T that may be interned at the specified scope to reduce heap consumption
        Parameters:
        charValue -
        cacheScope -
        trabsform -
        Returns:
        a possibly interned instance of T
      • apply

        public java.lang.String apply​(java.lang.String stringValue)
        returns a String that may be interned at the app-scope to reduce heap consumption
        Specified by:
        apply in interface java.util.function.Function<java.lang.String,​java.lang.String>
        Parameters:
        stringValue -
        Returns:
        a possibly interned String
      • apply

        public java.lang.String apply​(java.lang.String stringValue,
                                      DeserializerStringCache.CacheScope cacheScope)
        returns a String that may be interned at the given scope to reduce heap consumption
        Parameters:
        stringValue -
        cacheScope -
        Returns:
        a possibly interned String
      • size

        public int size()