Validate Ticket Dto Mapper

In this lesson, we're going to create the DTOs and mappers that we need in order to implement our validate ticket endpoint.

Creating the Request DTO

The TicketValidationRequestDto is a simple data class that carries validation request information.

@Data @AllArgsConstructor @NoArgsConstructor public class TicketValidationRequestDto { private UUID id; private TicketValidationMethod method; }

The class has two fields:

  • An id field of type UUID which can represent either a QR code ID or a ticket ID
  • A method field of type TicketValidationMethod enum to specify the validation method

Creating the Response DTO

The TicketValidationResponseDto represents the result of a ticket validation attempt.

@Data @AllArgsConstructor @NoArgsConstructor public class TicketValidationResponseDto { private UUID ticketId; private TicketValidationStatusEnum status; }

This class contains:

  • A ticketId field to identify the validated ticket
  • A status field using TicketValidationStatusEnum to indicate the validation result

Implementing the Mapper

The TicketValidationMapper interface handles the conversion between domain objects and DTOs.

@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) public interface TicketValidationMapper { @Mapping(target = "ticketId", source = "ticket.id") TicketValidationResponseDto toTicketValidationResponseDto(TicketValidation ticketValidation); }

The mapper has a single method that:

  • Takes a TicketValidation domain object as input
  • Maps it to a TicketValidationResponseDto
  • Uses @Mapping to specify that the ticketId field should come from ticket.id

Summary

  • Added TicketValidationRequestDto and TicketValidationResponseDto DTO classes
  • Added the mapping method toTicketValidationResponseDto to TicketValidationMapper
© 2026 Devtiro Ltd. All rights reserved