dimanche 20 décembre 2020

How to handle Multiple inherited DTOs in a single controller / service method?

I have got PaymentTransactionDTO as superclass and subclasses like PhoneBillPaymentTransactionDTO which has a field as phoneNumber etc.

and I would like to handle these DTOs from single payment service. My controller method like below;

public ResponseEntity<TransactionStatus> payment(@PathVariable String accountNumber,
        @Valid @RequestBody PaymentTransactionDTO paymentTransactionDTO)

When I post PhoneBillPaymentTransactionDTO to the method above, I can't reach phoneNumber field as I have PaymentTransactionDTO in the method signature.

How should I have a design to manage multiple inherited dtos from single method ?

Aucun commentaire:

Enregistrer un commentaire