Skip to content
Advertisement

MapStruct adding 1 suffix to object

I am using mapstruct to map my DTO to entity,

My Entity

@Entity
@Data
@Table(name = "break")
public class Break {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "native")
    private long id;
    
    private String name;
    private LocalDateTime start;
    private LocalDateTime end;
}

My DTO

@Data
public class BreakDTO {
    private String name;
    private LocalDateTime start;
    private LocalDateTime end;
}

Generated MapStruct Implementation

@Override
    public Break breakDTOtoBreak(BreakDTO breakDTO) {
        if ( breakDTO == null ) {
            return null;
        }

        Break break1 = new Break();

        break1.setName( breakDTO.getName() );
        break1.setStart( breakDTO.getStart() );
        break1.setEnd( breakDTO.getEnd() );

        return break1;
    }

I tried editing the file but it is unable to create break and always gives break1

Advertisement

Answer

Break is a reserved keyboard, use different name or it would always add 1 suffix for successful compilation.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement