I am developing a simple Rest API with Spring Boot 2.1.4 and Gradle 5.0
. I am using Lombok v1.18.6
to build my classes but when I call the services I am receiving an empty object
I tried adding the getters and setters methods manually and it fixed the problem but I would like to know why lombok
is not working in my project.
Also, my IDE is identifying properly the lombok pluging. I am using IntelliJ IDEA
My gradle dependency:
compileOnly 'org.projectlombok:lombok:1.18.6'
annotationProcessor 'org.projectlombok:lombok:1.18.6'
My model class:
@Entity
@Data
public class Category implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id_category")
private int idCategory;
@NotBlank
private String name;
@OneToMany(mappedBy = "category", cascade = CascadeType.ALL, orphanRemoval = true)
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private List<Language> languages;
}
My RestController:
@RestController
@RequestMapping("/categories")
public class CategoryController {
@Autowired
private CategoryService categoryService;
@GetMapping
public ResponseEntity<List<Category>> findAllCategories(){
List<Category> categories = categoryService.findAll();
return new ResponseEntity<List<Category>>(categories, HttpStatus.OK);
}
}
I am receiving this response:
[
{
"languages": []
}
]
But what I am expecting to receive is:
[
{
"idCategory": 1,
"name": "Backend"
"languages": []
}
]
Actually, I find weird that the only attribute that is being shown is languages
, that has the @JsonProperty
annotation, why is this happening?
UPDATE
I just realized that my IDE (IntelliJ) is recognizing the lombok pluging and I also have annotation processing enabled but when I try to excecute my code using a getter or an setter, it throws an error:
Error:(18, 26) java: cannot find symbol
symbol: method setName(java.lang.String)
location: class com.ramonparis.cvmanager.model.Category