Interface CustomColumnMapper


public interface CustomColumnMapper
Enables per-column ResultSet mapping customization via ResultSetMapper.
Since:
3.0.0
Author:
Mark Allen
  • Method Details

    • map

      @NonNull CustomColumnMapper.MappingResult map(@NonNull StatementContext<?> statementContext, @NonNull ResultSet resultSet, @NonNull Object resultSetValue, @NonNull TargetType targetType, @NonNull Integer columnIndex, @Nullable String columnLabel, @NonNull InstanceProvider instanceProvider) throws SQLException
      Perform custom mapping of a ResultSet column: given a resultSetValue, optionally return an instance of targetType instead.

      This method is only invoked when resultSetValue is non-null.

      Parameters:
      statementContext - current SQL context
      resultSet - the ResultSet from which data was read
      resultSetValue - the already-read value from the ResultSet, to be optionally converted to an instance of targetType
      targetType - the type to which the resultSetValue should be converted
      columnIndex - 1-based column index
      columnLabel - normalized column label, if available
      instanceProvider - instance-creation factory, may be used to instantiate values
      Returns:
      the result of the custom column mapping operation - either CustomColumnMapper.MappingResult.of(Object) to indicate a successfully-mapped value or CustomColumnMapper.MappingResult.fallback() if Pyranid should fall back to the registered ResultSetMapper mapping behavior.
      Throws:
      SQLException - if an error occurs during mapping
    • appliesTo

      Specifies which types this mapper should handle.

      For example, if this mapper should apply when marshaling to MyCustomType, this method could return targetType.matchesClass(MyCustomType.class).

      For parameterized types like List<UUID>, this method could return targetType.matchesParameterizedType(List.class, UUID.class).

      Parameters:
      targetType - the target type to evaluate - should this mapper handle it or not?
      Returns:
      true if this mapper should handle the type, false otherwise.