Skip to content

Add documentation about the Builders support #1417

Closed
@filiphr

Description

@filiphr
Member

How a builder is detect?
How are builder create method and build method detected?

Activity

added this to the 1.3.0.Beta1 milestone on Apr 4, 2018
soberich

soberich commented on Apr 5, 2018

@soberich

Well, being in snapshot channel you have to be ready to see a red bar...
It does not build now.
Many of my simple DTO annotated like this

@JsonInclude(NON_DEFAULT)
@JsonAutoDetect(fieldVisibility = ANY)
@JsonDeserialize(builder = AddressDTOBuilder.class)

@Getter
@Setter
@Builder(toBuilder = true)
@Accessors(fluent = true)
@NoArgsConstructor
@AllArgsConstructor
public final class AddressDTO {

    private Long id;

    @NotBlank
    private String town;

    @NotNull
    private Locale locale;

    @NotBlank
    private String street;

    @NotBlank
    private String zip;

    @JsonPOJOBuilder(withPrefix = "")
    public static final class AddressDTOBuilder {
    }
}

Primarily this was done (adopted) to have a Mapstruct support.
And I may say that this become even comfortable for some cases, to have both builder and fluent accessors.
Now the build fails, saying Can't generate mapping method when @MappingTarget is supposed to be immutable (has a builder).
JPA by the way has same

@Getter
@Setter
@Builder(toBuilder = true)
@Accessors(fluent = true)
@NoArgsConstructor
@AllArgsConstructor

JPA has some requirements as you know,
And as it were annotated pretty much the same way the mapping with mapstruct was very easy,
and know, how to map them? The DTO Ideally should become immutable with Value (but NOT nesseseraly, since they were not till now), but now as it fails, we'll have to rewrite anyway.

filiphr

filiphr commented on Apr 5, 2018

@filiphr
MemberAuthor

I feel you @soberich. What can you do is to use jitpack.io with this commit which is before the builder stuff.

In any case you are right we would need to fix something like this. At this moment there are 2 options that could be done:

  • You can still pass in a builder to provide the update mappings
  • We can relax that error and when we have a @MappingTarget we try to update that type and not do such strong assumption. (Can you open an issue for this?)

By the way fluent accessor would work now for non builders as well. As a method is considered as a setter when it returns itself, has a single parameter and does not start with get, is or set.

added a commit that references this issue on Apr 6, 2018

mapstruct#1417 Add documentation about the builder support

self-assigned this
on Apr 6, 2018
added a commit that references this issue on Apr 15, 2018

#1417 Add documentation about the builder support

43a9419
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @filiphr@soberich

      Issue actions

        Add documentation about the Builders support · Issue #1417 · mapstruct/mapstruct