Class KiwiMultivaluedMaps

java.lang.Object
org.kiwiproject.jaxrs.KiwiMultivaluedMaps

public final class KiwiMultivaluedMaps extends Object
Static utilities for working with MultivaluedMap instances.
  • Method Details

    • newMultivaluedMap

      public static jakarta.ws.rs.core.MultivaluedMap<String,String> newMultivaluedMap(String... items)
      Create a new MultivaluedMap from the given items, which are expected to be in alternating key/value pairs. This allows for keys to be repeated, i.e. so that a single key can have multiple values.
      Parameters:
      items - the keys and values, e.g. key1, value1, key2, value2, ...
      Returns:
      a new MultivaluedMap
      Implementation Note:
      the actual type returned is currently a MultivaluedHashMap
    • newSingleValuedParameterMap

      public static jakarta.ws.rs.core.MultivaluedMap<String,String> newSingleValuedParameterMap(String... items)
      Create a new MultivaluedMap from the given items, which are expected to be in alternating key/value pairs.

      NOTE: Unlike newMultivaluedMap(String...), this method assumes you want only one value per key, even if items contains multiple values per key. In that case, the last value in items associated with a given key is the one that "wins" and stays in the returned map.

      Parameters:
      items - the keys and values, e.g. key1, value1, key2, value2, ...
      Returns:
      a new MultivaluedMap
      Implementation Note:
      the actual type returned is currently a MultivaluedHashMap
    • toSingleValuedParameterMap

      public static Map<String,String> toSingleValuedParameterMap(jakarta.ws.rs.core.MultivaluedMap<String,String> original)
      Converts the given MultivaluedMap to a single-valued JDK Map by getting only the first element for each key in the multivalued map. This means that if there are keys having multiple values, elements past the first one are ignored.
      Parameters:
      original - the original multivalued map to convert
      Returns:
      the single-valued JDK map
    • toMultimap

      public static com.google.common.collect.Multimap<String,String> toMultimap(jakarta.ws.rs.core.MultivaluedMap<String,String> original)
      Convert the given MultivaluedMap into a Guava Multimap.
      Parameters:
      original - the original multivalued map to convert
      Returns:
      the Guava multimap