Home > database >  MapStruct adding 1 suffix to object
MapStruct adding 1 suffix to object

Time:10-10

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

CodePudding user response:

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

CodePudding user response:

break is a reserved keyword in java used to terminate loops and switch statements in java and it is reserved for that purpose that is why you are unable to create variable with name break. You can checkout reserved keywords in java from below link:

https://www.thoughtco.com/reserved-words-in-java-2034200

  • Related