0
public class ModelMapper implements ResultSetMapper<Model> {
    public Model map(int index, ResultSet resultSet, StatementContext ctx) throws SQLException {
        // Get result set meta data & column count
        ResultSetMetaData metaData = resultSet.getMetaData();
        int columns = metaData.getColumnCount();

        Map<String, Object> map = new HashMap<>(columns);
        for (int i = 1; i <= columns; ++i) {
            String columnName = metaData.getColumnName(i);
            map.put(columnName, resultSet.getObject(columnName));
        }

        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);

        return objectMapper.convertValue(map, Model.class);
    }
}

In my ModelImplDao.class I have registered it as @RegisterMapper(ModelMapper.class). Since I can see that ModelMapper class there is exactly one parameter Model, how can I create a class that would be generic and parameterised to take Model as a parameter and I am also able to register it in ModelImplDao.class as a mapper?

Viveran
  • 83
  • 1
  • 14

1 Answers1

0

We can't use ResultMapper where T is generic. It needs to know the type. Alternatively you can use this library (http://manikandan-k.github.io/jdbi_folder/). It provides a way remove the mappers. This library will take care of mapping.

Manikandan
  • 3,025
  • 2
  • 19
  • 28