Lombok
20 questions in 6 subtopics.
Lombok annotations: @Data, @Value, getters and setters
What code does Lombok generate for@Data and for @Value? How does Lombok generate code at all, given that Java has no macros?A class Order is annotated @Data and stored in a HashSet. After calling order.setStatus(SHIPPED), set.contains(order) returns false. Explain and fix.During a code review you find a class hierarchy where class Admin extends User, both annotated @Data, and admins with different permissions compare as equal. What is wrong and what is the right configuration?A static analysis report shows that 60 percent of your company's Java classes use @Data, including entities, DTOs and services with injected dependencies. What guidelines would you set for Lombok use?@Builder
Annotate a class Customer with@Builder so that name is required, tags defaults to an empty list, and you can add single tags with .tag("vip"). Show the code and a usage, and explain why fields with initialisers need @Builder.Default.After adding @Builder to an existing class that had a no-args constructor used by Jackson and JPA, deserialisation fails with 'Cannot construct instance (no Creators, like default constructor, exist)'. Explain and fix.Teams use @Builder on domain objects in a large codebase, and invalid objects (missing required fields) reach the database. How would you change object construction practices without a rewrite?Public SDKs your company ships to customers use Lombok-generated builders, and changes in Lombok or field order have broken binary compatibility for customers. How do you set API design rules for published libraries?IDE and build setup
How do you set up Lombok correctly in a Maven or Gradle project and in IntelliJ IDEA? What breaks if it is on the compile classpath but not configured as an annotation processor?After upgrading to a new JDK, the build fails with errors like 'java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment'. What is going on and how do you handle it?Your company has 15 million lines of Java and Lombok is used in most of it. An architect proposes removing Lombok completely because it depends on compiler internals. How do you evaluate and, if chosen, execute this?Lombok with Jackson
Make this immutable Lombok class deserialise with Jackson:@Value
@Builder
public class Address {
String street;
String city;
}
isPublished with @Data. The JSON output contains 'published' instead of 'isPublished', and incoming JSON with 'isPublished' is ignored. Explain and fix.Different services serialise the same Lombok DTOs from a shared library in different JSON shapes, because some apply naming strategies and others rely on Lombok config flags. How would you fix this across 25 services?Lombok with JPA entities
An entity Order with@Data has a @OneToMany List<OrderLine> lines, and OrderLine has @ManyToOne Order order, also with @Data. Logging an order throws StackOverflowError. Why, and what other problems does @Data cause on entities?Write the recommended equals and hashCode for a JPA entity with a generated Long id, and explain why Lombok's default does not work with Hibernate proxies.You are writing the persistence coding standard for 40 teams using Spring Data JPA. What will it say about Lombok on entities and why?Records vs Lombok
Compare a Java record with a Lombok@Value class. When would you still choose Lombok?A team wants to replace all Lombok @Value DTOs with records in a service with 300 DTOs that are serialised to JSON and used in Thymeleaf templates and MapStruct mappers. What do you check before and during the change?Java added records, pattern matching and other features that cover much of what Lombok was used for. How should a long-lived company codebase respond to language features replacing popular libraries, using Lombok as the example?No question matches these choices.