The following mapper configuration works fine (MyPojo has no other constructor)
class MyPojo {
private Long id;
private String name;
// No constructor
}
DynamicJdbcMapper<MyPojo> mapper = JdbcMapperFactory.newInstance().addKeys("id").newMapper(MyPojo.class);
ResultQuery<?> query = dsl
.select(
MY_TABLE.ID.as("id"),
MY_TABLE.NAME.as("name"))
.from(MY_TABLE).where(MY_TABLE.ID.eq(1));
MyPojo pojo = mapper.stream(query.fetchResultSet()).findFirst().orElse(null);
But in my case MyPojo is a legacy class and comes with a whole bunch of constructors:
class MyPojo {
private Long id;
private String name;
public MyPojo(Long id) {
this.id = id;
}
}
This causes the mapper to not work. I get the following error:
Could not find eligible property for 'name' on class com.bla.bla.MyPojo
It is apparent that the mapper is trying to look for a constructor with argument matching each of the column in the SELECT clause. I don't want to add overloaded constructors (the SELECT column list is huge).
How do set up the mapper to invoke the setters as opposed to a constructor?