title: How to deserialize from Number value to int (error - no int/Int-argument constructor/factory method to deserialize from Number value)
body: <p>I have two classes <code>Flight</code> and <code>Ticket</code>. One flight can has lots of tickets, so <code>Ticket</code> has foreign key <code>flight_id</code>.</p>
  
  <p>Here is my database with tables <code>flight</code> and <code>ticket</code>.</p>
  
  <p><a href="https://i.stack.imgur.com/ZwhKi.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ZwhKi.png" alt="enter image description here"></a></p>
  
  <p>Here is my <code>json request</code> (from Mozilla debugger), which I want to save in the database.</p>
  
  <p><a href="https://i.stack.imgur.com/vuD9v.png" rel="noreferrer"><img src="https://i.stack.imgur.com/vuD9v.png" alt="enter image description here"></a></p>
  
  <p>You can see <code>flight_id</code> parameter, but I can't save it to my database, I've got such an error: </p>
  
  <p><code>at [Source: (PushbackInputStream); line: 1, column: 53] (through reference chain: dto.TicketDto["flight_id"]) DefaultHandlerExceptionResolver : Failed to read HTTP message: 
  org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot construct instance of</code>model.Flight<code>(although at least one Creator exists): no int/Int-argument constructor/factory method to deserialize from Number value (199); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of</code>model.Flight<code>(although at least one Creator exists): no int/Int-argument constructor/factory method to deserialize from Number value</code></p>
  
  <p>Class Ticket:</p>
  
  <pre><code>@Entity
  @Table(name = "ticket")
  public class Ticket {
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private int ticket_id;
  
  @Column(name = "place")
  private int place;
  
  @Column(name = "name")
  private String name;
  
  @Column(name = "surname")
  private String surname;
  
  @JsonDeserialize(using = CustomParameterDeserializer.class)
  @ManyToOne(targetEntity = Flight.class)
  @JoinColumn(name = "flight_id")
  @JsonBackReference("flight")
  private Flight flight_id;
  
  // getters setters
  // constructor
  </code></pre>
  
  <p>Class TicketDto:</p>
  
  <pre><code>public class TicketDto {
  
  private int ticket_id;
  
  private int place;
  
  private String name;
  
  private String surname;
  
  private Flight flight_id;
  
  private Customer customer_id;
  
  // getters setters
  </code></pre>
  
  <p>My class Flight:</p>
  
  <pre><code>@Entity
  @Table(name = "flight")
  public class Flight {
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private int flight_id;
  
  //
  
  @OneToMany(mappedBy = "flight_id")
  @JsonManagedReference("flight")
  private List&lt;Ticket&gt; ticket;
  
  // getters setters
  </code></pre>
  
  <p>My class FlightDto:</p>
  
  <pre><code>public class FlightDto {
  private int flight_id;
  
  //
  
  private List&lt;TicketDto&gt; ticket;
  
  // getters setters
  </code></pre>
  
  <p>Here is the class TicketServiceImpl with the method to save my Ticket:</p>
  
  <pre><code>@Service
  public class TicketServiceImpl implements TicketService {
  
  @Autowired
  TicketRepository repository;
  
  @Override
  public Ticket save(TicketDto ticketDto) {
      Ticket ticket = new Ticket();
      ticket.setName(ticketDto.getName());
      ticket.setSurname(ticketDto.getSurname());
      ticket.setCustomer_id(ticketDto.getCustomer_id());
      ticket.setFlight_id(ticketDto.getFlight_id());
      ticket.setPlace(ticketDto.getPlace());
  
      return repository.save(ticket);
  }
  </code></pre>
  
  <p>My class ticket.ts in Angular:</p>
  
  <pre><code>export class Ticket {
  ticket_id: number;
  place: string;
  customer_id: number;
  flight_id: number;
  name: string;
  surname: string;
  }
  </code></pre>