2

I am trying to map CSV data row to FlightBooking bean, which has 2 nested beans of same type FlightSegment.
CSV header is below for reference:

Booking Date,Booking Reference,Total Price,Aviation Taxes,Flight Reference,Flight Date,Flight Price,Seat Reservation Price,Prepaid Meal Price,Flight Reference,Flight Date,Flight Price,Seat Reservation Price,Prepaid Meal Price

FlightBooking bean definition is below for reference:

public class FlightBooking {
    private String bookingReference;
    private String bookingDate;
    private String aviationTaxes;
    private String totalPrice;
    private FlightSegment segmentOut;
    private FlightSegment segmentReturn;
}

FlightSegment bean definition is below for reference:

public class FlightSegment {
    private String flightReference;
    private String flightDate;
    private String flightPrice;
    private String seatReservationPrice;
    private String prepaidMealPrice;
}

Columns 5 to 9 represent outwards leg of the flight and should be mapped to segmentOut.
Columns 10 to 14 represent return leg of the flight and should be mapped to segmentReturn.

Restrictions:
Bean Definitions cannot be altered.

I could have easily used OpenCSV 5.x @CsvRecurse if there were only one FlightSegment attribute in FlightBooking.

Please help.

VivekRatanSinha
  • 596
  • 1
  • 4
  • 17
  • Your scenario is very similar to the one in [this question](https://stackoverflow.com/questions/62281443/opencsv-with-complex-bean-structure/62365775#62365775). As you say, because of the two `FlightSegment`s at the same level, this limits your options a bit (even if you redesign the `FlightBooking` class, and add segment type to `FlightSegment`). – andrewJames Jun 16 '20 at 23:35

0 Answers0