You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.mapToBean() works wonders. However, this would require the bearing data class to be mutable. Protocol buffers, AutoValues, and other immutable data class helpers would be useless without additional mapping logic.
I feel .mapToBean() could have worked out of box for these cases (since the builder is a bean) by:
adding support for instance creation with their builders, instead of a default constructor.
returning an instance built from the builder, instead of itself (as in bean mapper's case).
Internally, the builders could use the BeanMapper's logic, i.e. with .setXxx() methods. The common build method I saw is .build(), which should be able to get reflectively called and return the built instance. Or, a user-defined Function to map the builder to the data instance can be used to allow customizations.
My proposal is to add sibling methods of .mapToBean() like these:
/** * Maps to a data type with its builder. * * <p>This would try to look for a `.build()` method in the builder to create the data instance. **/
<DataType, BuilderType> ResultIterable<DataType> mapToBuilder(Supplier<BuilderType> builderSupplier);
/** * Maps to a data type with its builder, with a provided `buildFunction` if the build method is not `build()`. **/
<DataType, BuilderType> ResultIterable<DataType> mapToBuilder(Supplier<BuilderType> builderSupplier, Function<BuilderType, DataType> buildFunction);
If Class<BuilderType> would be needed they could be added as well.
Example usage could be:
handle.createQuery("select * from my_table;").mapToBuilder(MyTypeWithBuilder::newBuilder).list();
handle.createQuery("select * from my_table;").mapToBuilder(MyTypeWithBuilder::newBuilder, MyTypeWithBuilder::buildInstance).list();
What do you say?
The text was updated successfully, but these errors were encountered:
.mapToBean()
works wonders. However, this would require the bearing data class to be mutable. Protocol buffers, AutoValues, and other immutable data class helpers would be useless without additional mapping logic.I feel
.mapToBean()
could have worked out of box for these cases (since the builder is a bean) by:Internally, the builders could use the
BeanMapper
's logic, i.e. with.setXxx()
methods. The common build method I saw is.build()
, which should be able to get reflectively called and return the built instance. Or, a user-definedFunction
to map the builder to the data instance can be used to allow customizations.My proposal is to add sibling methods of
.mapToBean()
like these:If
Class<BuilderType>
would be needed they could be added as well.Example usage could be:
What do you say?
The text was updated successfully, but these errors were encountered: