'mapstruct reporting unknown property but as far as i can tell its there

I have a fairly simple mapper

/**
 * Interface TicketLocationDetailsMapper that allows mapping between DTO and Domain and vice versa.
 *
 * @author Owen Gerig / Dev Team <br>
 *         created on 17 May 2022
 * @since 1.0.0
 */
@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR, unmappedSourcePolicy = ReportingPolicy.ERROR)
public interface TicketLocationDetailsMapper {

    /**
     * Converts TicketLocationDetails domain class to DTO
     *
     * @param TicketLocationDetails domain class
     * @return TicketLocationDetails DTO class. If null provided, would return null as well.
     */
    @Mapping(source = "location", target = "locationId", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_NULL)
    com.ticket.dto.TicketLocationDetails TicketLocationDetailsToDto(TicketLocationDetails TicketLocationDetails);

    /**
     * Converts TicketLocationDetails dto class to domain
     *
     * @param TicketLocationDetails domain class
     * @return TicketLocationDetails DTO class. If null provided, would return null as well.
     */
    @Mapping(source = "locationId", target = "location", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_NULL)
    TicketLocationDetails TicketLocationDetailsToDomain(com.ticket.dto.TicketLocationDetails TicketLocationDetails);

    /**
     * Converts domain class to DTO field. dto only holds id where as domain has full object so this extra mapping is needed
     *
     * @param location location domain class
     * @return location ID. If null provided, would return null as well.
     * @since 1.0.0
     */
    static UUID locationToId(TicketLocation location) {
        return location.getId();
    }

    /**
     * Converts location ID param to a new location with its id populated. dto only holds id where as domain has full object so this extra mapping is needed
     *
     *
     * @param locationId id of the location
     * @return newly created ticket TicketLocation object with its id populated. If null provided, would return null as well.
     * @since 1.0.0
     */
    static TicketLocation locationIdToLocation(UUID locationId) {
        TicketLocation location = new TicketLocation();
        location.setId(locationId);
        return location;
    }
}

My domain class:

@Entity
@Table(schema = "core", name = "location_details")
public class TicketLocationDetails {
    @JsonView(Views.Summary.class)
    private UUID id;
    private String contactName;
    @JsonIgnore
    private TicketLocation location;

    /**
     * Retrieves {@code contactName}
     *
     * @return contactName
     */
    @Column(name = "contact_email")
    public String getContactName() {
        return contactName;
    }

    /**
     * Sets {@code contactName}
     *
     * @param contactName the {@code contactName} field
     */
    public void setContactName(String contactName) {
        this.contactName = contactName;
    }

    /**
     * Retrieves {@code id}
     *
     * @return id
     */
    @Id
    @Column(name = "id")
    @Type(type = "pg-uuid")
    public UUID getId() {
        return this.id;
    }

    /**
     * Sets {@code id}
     *
     * @param id the {@code id} field
     */
    public void setId(UUID id) {
        this.id = id;
    }

    /**
     * Retrieves {@code location}
     *
     * @return location
     */
    @MapsId
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "id")
    public TicketLocation getLocation() {
        return this.location;
    }

    /**
     * Sets {@code location}
     *
     * @param location the {@code location} field
     */
    public void setLocation(TicketLocation location) {
        this.location = location;
    }
}

my DTO class:

public class TicketLocationDetails {
    @JsonView(Views.Summary.class)
    private UUID id;
    private String contactName;
    private UUID locationId;

    /**
     * Retrieves {@code contactName}
     *
     * @return contactName
     */
    public String getContactName() {
        return contactName;
    }

    /**
     * Sets {@code contactName}
     *
     * @param contactName the {@code contactName} field
     */
    public void setContactName(String contactName) {
        this.contactName = contactName;
    }

    /**
     * Retrieves {@code id}
     *
     * @return id
     */
    public UUID getId() {
        return this.id;
    }

    /**
     * Sets {@code id}
     *
     * @param id the {@code id} field
     */
    public void setId(UUID id) {
        this.id = id;
    }

    /**
     * Retrieves {@code locationId}
     *
     * @return locationId
     */
    public UUID getLocationId() {
        return locationId;
    }

    /**
     * Sets {@code locationId}
     *
     * @param id the {@code locationId} field
     */
    public void setLocationId(UUID locationId) {
        this.locationId = locationId;
    }

}

errors I receive on mvn clean install:

[ERROR] /C:/CodeRepos/work/github/symphony-tickets/src/main/java/com/ticket/mappers/TicketLocationDetailsMapper.java:[33,48] Unknown property "locationId" in result type TicketLocationDetails. Did you mean "id"? [ERROR] /C:/CodeRepos/work/github/symphony-tickets/src/main/java/com/ticket/mappers/TicketLocationDetailsMapper.java:[42,27] No property named "locationId" exists in source parameter(s). Did you mean "id"?

but I don't understand the fields are there?



Solution 1:[1]

this seems to have come about due to class names being the same, changing the dto to TicketLocationDetailsDto has resolved the issue

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 owen gerig