Scrivio Interview library

Lombok

20 questions in 6 subtopics.

Lombok annotations: @Data, @Value, getters and setters

ConceptFoundations6 min read
What code does Lombok generate for @Data and for @Value? How does Lombok generate code at all, given that Java has no macros?
DebuggingFoundations6 min read
A class Order is annotated @Data and stored in a HashSet. After calling order.setStatus(SHIPPED), set.contains(order) returns false. Explain and fix.
ScenarioIntermediate6 min read
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?
LeadershipAdvanced5 min read
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

CodingFoundations6 min read
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.
DebuggingIntermediate6 min read
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.
DesignAdvanced6 min read
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?
DesignPrincipal6 min read
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

ConceptFoundations6 min read
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?
DebuggingIntermediate6 min read
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?
LeadershipPrincipal6 min read
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

CodingFoundations6 min read
Make this immutable Lombok class deserialise with Jackson:
@Value
@Builder
public class Address {
String street;
String city;
}
Show two working approaches.
DebuggingIntermediate5 min read
A DTO has a field private boolean isPublished with @Data. The JSON output contains 'published' instead of 'isPublished', and incoming JSON with 'isPublished' is ignored. Explain and fix.
ScenarioAdvanced6 min read
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

DebuggingFoundations6 min read
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?
ConceptIntermediate7 min read
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.
DesignAdvanced7 min read
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

ConceptFoundations8 min read
Compare a Java record with a Lombok @Value class. When would you still choose Lombok?
ScenarioIntermediate7 min read
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?
LeadershipPrincipal6 min read
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?