emazzotta
emazzotta

Reputation: 2039

POJO Mapping in JOOQ regardless of parameter order

When I generate the JOOQ POJOs, the constructor follows the same order for the parameters as the fields in the database table.

When querying the table and using fetchInto this works fine, as long as the order of the POJO constructor parameters and the order of the fields in the database table are the same.

return create
      .select()
      .from(KEY)
      .fetchInto(Key.class);

How can I map the query above into Key.class regardless of the constructor parameter order? E.g. can I use something like mapstruct in conjunction with JOOQ?

Upvotes: 3

Views: 1055

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 220762

You can annotate your constructor with @java.beans.ConstructorProperties. We also support Java 8's parameter name reflection (see https://github.com/jOOQ/jOOQ/issues/4627), but that does not seem as reliable, as it depends on flags you set when compiling your own code.

See also the documentation of DefaultRecordMapper.

Upvotes: 1

Related Questions