JdbcRecordMapper extends AbstractRecordMapper<P> implements RecordMapper<ResultSet, P> { @Override public Record<P> processRecord(final Record<ResultSet> record) throws Exception { ResultSet resultSet = record.getPayload(); initFieldNames(resultSet); Map<String, String> values = new HashMap<>(); for (int i = 0; i < fields.length; i++) { values.put(fields[i], resultSet.getString(i + 1)); } return new GenericRecord<>(record.getHeader(), objectMapper.mapObject(values)); } JdbcRecordMapper(final Class<P> recordClass);  JdbcRecordMapper(final Class<P> recordClass, final String... fields); @Override Record<P> processRecord(final Record<ResultSet> record);  }
@Test public void testMapRecordWithDefaultMapping() throws Exception { tweetMapper = new JdbcRecordMapper<>(Tweet.class); when(metadata.getColumnLabel(1)).thenReturn("id"); when(metadata.getColumnLabel(2)).thenReturn("user"); when(metadata.getColumnLabel(3)).thenReturn("message"); Record<Tweet> actual = tweetMapper.processRecord(jdbcRecord); Tweet tweet = actual.getPayload(); assertThat(tweet).isEqualTo(new Tweet(1, "foo", "Hello!")); }
@Test public void testMapRecordWithCustomMapping() throws Exception { tweetMapper = new JdbcRecordMapper<>(Tweet.class, "id", "user", "message"); Record<Tweet> actual = tweetMapper.processRecord(jdbcRecord); Tweet tweet = actual.getPayload(); assertThat(tweet).isEqualTo(new Tweet(1, "foo", "Hello!")); }