Skip to content

Exception: “enum” does not have an accessible constructor #2421

@khodabandelu

Description

@khodabandelu

When I upgrade Mapstruct from "1.3.1.Final" to "1.4.2.Final" , I face this error.
CompanyType does not have an accessible constructor.
Mapstruct cannot map enum to string in this version of Mapstruct and all of my mapping class face this error. and I need this version because of some features of this version.
please help me to solve this exception.

My code :

@Entity
@Getter
@Setter
@Table(name = "CORE_COMPANY")
@NoArgsConstructor
@AllArgsConstructor
public class Company  {

    @Id
    @GeneratedValue(generator = "uuid2")
    @GenericGenerator(name = "uuid2", strategy = "uuid2")
    private String id;

    @NotNull
    @Size(min = 2, max = 50)
    @Column(name = "NAME", nullable = false)
    private String name;

    @NotNull
    @Column(name = "ADDRESS", nullable = false)
    private String address;

    @NotNull
    @Enumerated(EnumType.STRING)
    @Column(name = "COMPANY_TYPE", nullable = false)
    private CompanyType companyType;

    @Column(name = "IS_ACTIVE")
    private Boolean active;

}

@Getter
@AllArgsConstructor
public enum CompanyType {
    insurance("Insurance", "insurance"),
    inspection("Inspection", "inspectionem"),
    Shipping("Shipping", "naviportans");

    private final String title;
    private final String latinTitle;
}

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class CompanyDTO  {
    private String id;
    private String name;
    private String address;
    private String companyType;
    private String companyTypeLatinTitle;
    private Boolean active;
}


@Mapper(componentModel = "spring")
public interface CompanyMapper extends EntityMapper<CompanyDTO, Company> {
    CompanyMapper INSTANCE = Mappers.getMapper(CompanyMapper.class);

    @Mapping(target = "companyTypeLatinTitle", source = "companyType.latinTitle")
    @Mapping(target = "countryId", source = "country.id")
    @Mapping(target = "countryTitle", source = "country.title")
    CompanyDTO toDto(Company entitiy) ;

    @InheritInverseConfiguration
    Company toEntity(CompanyDTO dto) ;

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions