assembler icon indicating copy to clipboard operation
assembler copied to clipboard

Support relevant subset of JPA annotations

Open pellse opened this issue 7 years ago • 0 comments

If the POJOs returned from the different method calls to be assembled declare JPA annotation e.g. @Id, @OneToOne, etc., it would be nice to honor those, this would allow to simplify the Assembler API invocation as it wouldn't be mandatory to supply an id extractor function:

So the following:

@Data
@AllArgsConstructor
public class Transaction {
    private final Customer customer;
    private final BillingInfo billingInfo;
    private final List<OrderItem> orderItems;
}

Flux<Transaction> transactionFlux = FluxAssembler.of(this::getCustomers, Customer::getCustomerId)
    .assemble(
        oneToOne(this::getBillingInfoForCustomers, BillingInfo::getCustomerId),
        oneToManyAsList(this::getAllOrdersForCustomers, OrderItem::getCustomerId),
        Transaction::new);

could instead be declared as:

Flux<Transaction> transactionFlux = FluxAssembler.of(this::getCustomers)
    .assemble(
        oneToOne(this::getBillingInfoForCustomers),
        oneToManyAsList(this::getAllOrdersForCustomers,
        Transaction::new);

The idea of providing an id extractor function being actually to avoid to have to support annotations and make the framework a lot more flexible by being able to join/assemble arbitrary data sources, full support for id extraction functions should still be there, and explicitly providing id extraction functions should override the mapping declared in JPA annotations.

pellse avatar May 08 '18 15:05 pellse