Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation about the Builders support #1417

Closed
filiphr opened this issue Apr 4, 2018 · 2 comments
Closed

Add documentation about the Builders support #1417

filiphr opened this issue Apr 4, 2018 · 2 comments
Assignees
Milestone

Comments

@filiphr
Copy link
Member

filiphr commented Apr 4, 2018

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

@filiphr filiphr added this to the 1.3.0.Beta1 milestone Apr 4, 2018
@soberich
Copy link

soberich commented Apr 5, 2018

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
Copy link
Member Author

filiphr commented Apr 5, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants