title: Post Method using DTO
body: <p>I want to use DTO to communicate with the Angular, but actually it doesn't work. I want to create POST request to add data from my application to the database using Dto model. </p>
  
  <p>You can see my errors on the picture:
  <a href="https://i.stack.imgur.com/yCvHv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yCvHv.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/N2gMH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N2gMH.png" alt="enter image description here"></a></p>
  
  <p>My class Customer:</p>
  
  <pre><code>@Entity
  @Table(name = "customer")
  public class Customer {
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private int id;
  
  @Column(name = "name")
  private String name;
  
  @OneToMany
  private List&lt;Ticket&gt; ticket;
  ...
  </code></pre>
  
  <p>Class CustomerDto:</p>
  
  <pre><code>public class CustomerDto {
  private String name;
  private List&lt;TicketDto&gt; ticket;
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  public List&lt;TicketDto&gt; getTicket() {
      return ticket;
  }
  
  public void setTicket(List&lt;TicketDto&gt; ticket) {
      this.ticket = ticket;
  }
  }
  </code></pre>
  
  <p>Class CustomerController:</p>
  
  <pre><code>@Autowired
  CustomerService customerService;
  
  @PostMapping(value = "/customers/create")
  public Customer postCustomer(@RequestBody CustomerDto customerDto, List&lt;TicketDto&gt; ticketDtos) {
      //ArrayList&lt;TicketDto&gt; tickets = new ArrayList&lt;&gt;();
      ticketDtos.add(customerDto.getName());
      ticketDtos.add(customerDto.getTicket());
      Customer _customer = customerService.save(new Customer(customerDto.getName(), ticketDtos ));
      return _customer;
  }
  </code></pre>
  
  <p>CustomerService:</p>
  
  <pre><code>public interface CustomerService {
  
  void save(CustomerDto customerDto, List&lt;TicketDto&gt; ticketDtos);
  }
  </code></pre>
  
  <p>CustomerServiceImpl:</p>
  
  <pre><code>@Service
  public class CustomerServiceImpl implements CustomerService {
  
  @Autowired
  CustomerRepository repository;
  
  @Override
  public void save(CustomerDto customerDto, List&lt;TicketDto&gt; ticketDtos) {
      Customer customer = new Customer();
      customer.setName(customerDto.getName());
      customer.setTicket(customerDto.getTicket());
  
      List&lt;Ticket&gt; tickets = new ArrayList&lt;&gt;();
      for (TicketDto ticketDto : ticketDtos) {
          Ticket ticket = new Ticket();
          ticket.setDestinationCity(ticketDto.getDepartureCity());
          ticket.setDestinationCity(ticketDto.getDestinationCity());
          tickets.add(ticket);
      }
  }
  </code></pre>