java.lang.Object
org.springframework.data.redis.connection.convert.Converters
Direct Known Subclasses:
LettuceConverters

public abstract class Converters extends Object
Common type converters
Author:
Jennifer Hickey, Thomas Darimont, Mark Paluch, Christoph Strobl, John Blum, Sorokin Evgeniy
  • Constructor Details

    • Converters

      public Converters()
  • Method Details

    • identityConverter

      public static <T> org.springframework.core.convert.converter.Converter<T,T> identityConverter()
      Returns a Converter that always returns its input argument.
      Type Parameters:
      T - the type of the input and output objects to the function
      Returns:
      a function that always returns its input argument
      Since:
      2.5
    • stringToBoolean

      public static Boolean stringToBoolean(String source)
    • stringToBooleanConverter

      public static org.springframework.core.convert.converter.Converter<String,Boolean> stringToBooleanConverter()
    • stringToProps

      public static org.springframework.core.convert.converter.Converter<String,Properties> stringToProps()
    • longToBoolean

      public static org.springframework.core.convert.converter.Converter<Long,Boolean> longToBoolean()
    • stringToDataType

      public static org.springframework.core.convert.converter.Converter<String,DataType> stringToDataType()
    • toProperties

      public static Properties toProperties(String source)
    • toProperties

      public static Properties toProperties(Map<?,?> source)
    • toBoolean

      public static Boolean toBoolean(@Nullable Long source)
    • toDataType

      public static DataType toDataType(String source)
    • toBit

      public static byte[] toBit(Boolean source)
    • toClusterNode

      protected static RedisClusterNode toClusterNode(String clusterNodesLine)
      Converts the result of a single line of CLUSTER NODES into a RedisClusterNode.
      Parameters:
      clusterNodesLine -
      Returns:
      Since:
      1.7
    • toSetOfRedisClusterNodes

      public static Set<RedisClusterNode> toSetOfRedisClusterNodes(Collection<String> lines)
      Converts lines from the result of CLUSTER NODES into RedisClusterNodes.
      Parameters:
      lines -
      Returns:
      Since:
      1.7
    • toSetOfRedisClusterNodes

      public static Set<RedisClusterNode> toSetOfRedisClusterNodes(String clusterNodes)
      Converts the result of CLUSTER NODES into RedisClusterNodes.
      Parameters:
      clusterNodes -
      Returns:
      Since:
      1.7
    • toObjects

      public static List<Object> toObjects(Set<Tuple> tuples)
    • toTimeMillis

      public static Long toTimeMillis(String seconds, String microseconds)
      Returns the timestamp constructed from the given seconds and microseconds.
      Parameters:
      seconds - server time in seconds
      microseconds - elapsed microseconds in current second
      Returns:
    • toTimeMillis

      public static Long toTimeMillis(String seconds, String microseconds, TimeUnit unit)
      Returns the timestamp constructed from the given seconds and microseconds.
      Parameters:
      seconds - server time in seconds.
      microseconds - elapsed microseconds in current second.
      unit - target unit.
      Returns:
      Since:
      2.5
    • secondsToTimeUnit

      public static long secondsToTimeUnit(long seconds, TimeUnit targetUnit)
      Converts seconds to the given TimeUnit.
      Parameters:
      seconds -
      targetUnit - must not be null.
      Returns:
      Since:
      1.8
    • secondsToTimeUnit

      public static org.springframework.core.convert.converter.Converter<Long,Long> secondsToTimeUnit(TimeUnit timeUnit)
      Creates a new Converter to convert from seconds to the given TimeUnit.
      Parameters:
      timeUnit - muist not be null.
      Returns:
      Since:
      1.8
    • millisecondsToTimeUnit

      public static long millisecondsToTimeUnit(long milliseconds, TimeUnit targetUnit)
      Converts milliseconds to the given TimeUnit.
      Parameters:
      milliseconds -
      targetUnit - must not be null.
      Returns:
      Since:
      1.8
    • millisecondsToTimeUnit

      public static org.springframework.core.convert.converter.Converter<Long,Long> millisecondsToTimeUnit(TimeUnit timeUnit)
      Creates a new Converter to convert from milliseconds to the given TimeUnit.
      Parameters:
      timeUnit - must not be null.
      Returns:
      Since:
      1.8
    • deserializingGeoResultsConverter

      public static <V> org.springframework.core.convert.converter.Converter<org.springframework.data.geo.GeoResults<RedisGeoCommands.GeoLocation<byte[]>>,org.springframework.data.geo.GeoResults<RedisGeoCommands.GeoLocation<V>>> deserializingGeoResultsConverter(RedisSerializer<V> serializer)
      Converter capable of deserializing GeoResults.
      Parameters:
      serializer -
      Returns:
      Since:
      1.8
    • distanceConverterForMetric

      public static org.springframework.core.convert.converter.Converter<Double,org.springframework.data.geo.Distance> distanceConverterForMetric(org.springframework.data.geo.Metric metric)
      Converter capable of converting Double into Distance using given Metric.
      Parameters:
      metric -
      Returns:
      Since:
      1.8
    • toProperties

      public static Properties toProperties(List<String> input)
      Converts array outputs with key-value sequences (such as produced by CONFIG GET) from a List to Properties.
      Parameters:
      input - must not be null.
      Returns:
      the mapped result.
      Since:
      2.0
    • listToPropertiesConverter

      public static org.springframework.core.convert.converter.Converter<List<String>,Properties> listToPropertiesConverter()
      Returns a converter to convert array outputs with key-value sequences (such as produced by CONFIG GET) from a List to Properties.
      Returns:
      the converter.
      Since:
      2.0
    • mapToPropertiesConverter

      public static <K, V> org.springframework.core.convert.converter.Converter<Map<K,V>,Properties> mapToPropertiesConverter()
      Returns a converter to convert from Map to Properties.
      Returns:
      the converter.
      Since:
      2.0
    • secondsToDuration

      @Nullable public static Duration secondsToDuration(@Nullable Long seconds)
      Convert the given nullable seconds to a Duration or null.
      Parameters:
      seconds - can be null.
      Returns:
      given seconds as Duration or null.
      Since:
      2.1
    • parse

      public static <T> T parse(Object source, Class<T> targetType)
      Parse a rather generic Redis response, such as a list of something into a meaningful structure applying best effort conversion of byte[] and ByteBuffer.
      Type Parameters:
      T -
      Parameters:
      source - the source to parse
      targetType - eg. Map, String,...
      Returns:
      Since:
      2.3
    • parse

      public static Object parse(Object source, String sourcePath, Map<String,Class<?>> typeHintMap)
      Parse a rather generic Redis response, such as a list of something into a meaningful structure applying best effort conversion of byte[] and ByteBuffer based on the sourcePath and a typeHintMap
      Parameters:
      source - the source to parse
      sourcePath - the current path (use "root", for level 0).
      typeHintMap - source path to target type hints allowing wildcards (*).
      Returns:
      Since:
      2.3
    • entryOf

      public static <K, V> Map.Entry<K,V> entryOf(K key, V value)
      Create an Map.Entry from key and value.
      Type Parameters:
      K -
      V -
      Parameters:
      key -
      value -
      Returns:
      Since:
      2.6