akshattandon / projectlombok

Automatically exported from code.google.com/p/projectlombok
0 stars 0 forks source link

combining @Data and @Builder remove the default constructor #781

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Please discuss feature requests first on
https://groups.google.com/forum/#!forum/project-lombok

What steps will reproduce the problem?
1. Combining @Data with @Builder delete the default constructor without args
@Data
@Builder
public class Foo {
  private String bar;
  public static void main (String[] args) {
     // I get compilation Error here
     Foo foo = new Foo();
  }
}

What is the expected output? What do you see instead?
I expect to have the default constructor without args, because my objects used 
by Jackson Mapper so Jackson instantiate my Objects using the default 
constructor not the Builder.

What version of the product are you using? On what operating system?
I am using:
- JDK 1.8
- Lombok 1.16.0
- eclipse juno
- Ubuntu Desktop 14.04

Original issue reported on code.google.com by amine.bouhamidi on 5 Feb 2015 at 7:04

GoogleCodeExporter commented 9 years ago
No idea about the exact rules, but in principle @Data implies a 
@NoArgsConstructor and @Builder implies an @AllArgsConstructor. In case a 
constructor already exists (possibly due to another annotation), this 
implication may or may not get omitted according to some subtle implementation 
details. In any case, I'd go for `@Data @Builder @NoArgsConstructor 
@AllArgsConstructor` to be sure as an explicit constructor annotation gets 
always honored.

Original comment by Maaarti...@gmail.com on 5 Feb 2015 at 5:57

GoogleCodeExporter commented 9 years ago
It works if I add @NoArgsConstructor @AllArgsConstructor.

But I suggest that combining @Data and @Builder will add implicitly both 
NoArgsConstructor and AllArgsConstructor to keep the code pretty and clean.

Original comment by amine.bouhamidi on 6 Feb 2015 at 3:03