Skip to content

Builder factory method still required when a builder is provided by an Object factory #1583

@Kabhal

Description

@Kabhal

Version : 1.3.0.Beta1

@Mapper
public abstract class PersonMapper {

   @Mapping(source = "id", target = "personId.id")
   public abstract Person personFromDto(PersonDto person);

   @InheritInverseConfiguration()
   public abstract PersonDto personToDto(Person person);

   // <1>
   public PersonId.Builder personIdBuilder() {
      return new PersonId.Builder();
   }
}

public class PersonId {
   private final Integer id;

   public PersonId(Integer id) {
      this.id = id;
   }
  
  // <2>
  public static Builder builder() {
      return new Builder();
   }

   public static class Builder {
      private Integer id;

      public Builder setId(Integer thatId) {
         this.id = thatId;
         return this;
      }

      public PersonId build() {
         return new PersonId(this.id);
      }
   }

<1> A builder is provided (the problem is the same when provided using a real Object factory referenced with 'uses')
<2> The builder factory method is required even for the mapper implementation to be generated, even if not used in the generated mapper.

The generated mapper correctly use the personIdBuilder method to create the builder, however, the annotation processor fails if the builder factory method does not exist in PersonId, with the following error :
Error:(17, 13) java: Property "personId.id" has no write accessor in com.tsquare.legalentity.domain.identity.Person.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions