Class GenericMapMapperFactory

java.lang.Object
org.jdbi.v3.core.mapper.GenericMapMapperFactory
All Implemented Interfaces:
RowMapperFactory

public class GenericMapMapperFactory extends Object implements RowMapperFactory
Factory for a RowMapper that can map resultset rows to column name/generic value Maps.

Each row in the resultset becomes a distinct Map, in which the keys are all distinct column names and the values are the corresponding cell contents. All values are mapped to the same generic type T (e.g. BigDecimal) by a ColumnMapper from the ConfigRegistry.

This differs from MapMapper by supporting a concrete type instead of only Object, and from collecting into a Map in that the latter maps an entire resultset to a single Map and can only keep 1 key and 1 value from each row.

Use cases for this are mainly single-row results like numeric reports (e.g. the price components, taxes, etc of a product for sale, or a set of possible labeled values for a user setting), and matrices.

See Also:
  • Constructor Details

    • GenericMapMapperFactory

      public GenericMapMapperFactory()
  • Method Details

    • build

      public Optional<RowMapper<?>> build(Type mapType, ConfigRegistry config)
      Description copied from interface: RowMapperFactory
      Supplies a row mapper which will map result set rows to type if the factory supports it; empty otherwise.
      Specified by:
      build in interface RowMapperFactory
      Parameters:
      mapType - the target type to map to
      config - the config registry, for composition
      Returns:
      a row mapper for the given type if this factory supports it; Optional.empty() otherwise.
      See Also:
    • getMapperForValueType

      public static <T> RowMapper<Map<String,T>> getMapperForValueType(Class<T> valueType, ConfigRegistry config)
      Returns a RowMapper for a map with the given value type. The key type is String.
      Type Parameters:
      T - The value type
      Parameters:
      valueType - A Class instance representing the value type for the Map
      config - A ConfigRegistry instance
      Returns:
      A RowMapper for a map from string to the given value type
    • getMapperForValueType

      public static <T> RowMapper<Map<String,T>> getMapperForValueType(GenericType<T> valueType, ConfigRegistry config)
      Returns a RowMapper for a map with the given value type. The key type is String.
      Type Parameters:
      T - The value type
      Parameters:
      valueType - A Class instance representing the value type for the Map
      config - A ConfigRegistry instance
      Returns:
      A RowMapper for a map from string to the given value type