{Project Lombok}
A java library that automatically plugs into your editor and build tools, spicing up you java
Using Lombok | Without Lombok
@Value
@Builder
@Jacksonized
public class AmazonDspAdGroup {
String adGroupId;
InventoryType inventoryType;
String name;
String purchaseOrderNumber;
String comments;
String campaignId;
@JsonSerialize(using = AmazonJsonUTCDateFormatSerializer.class)
@JsonDeserialize(using = AmazonJsonUTCDateFormatDeserializer.class)
LocalDateTime startDateTime;
@JsonSerialize(using = AmazonJsonUTCDateFormatSerializer.class)
@JsonDeserialize(using = AmazonJsonUTCDateFormatDeserializer.class)
LocalDateTime endDateTime;
CreativeRotationType creativeRotationType;
State state;
AdGroupDeliveryStatus deliveryStatus;
Bid bid;
Double budgetAmount;
List<BudgetCap> budgetCaps;
Pacing pacing;
List<Frequency> frequencies;
List<AdGroupFee> fees;
AdGroupOptimization optimization;
TargetingSettings targetingSettings;
List<String> advertisedProductCategoryIds;
@JsonSerialize(using = AmazonJsonUTCDateFormatSerializer.class)
@JsonDeserialize(using = AmazonJsonUTCDateFormatDeserializer.class)
LocalDateTime creationDateTime;
@JsonSerialize(using = AmazonJsonUTCDateFormatSerializer.class)
@JsonDeserialize(using = AmazonJsonUTCDateFormatDeserializer.class)
LocalDateTime lastUpdatedDateTime;
}
# CODE EXAMPLE
@JsonDeserialize(builder = AmazonLineItem.Builder.class)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AmazonLineItem {
private String lineItemId;
private LineItemType lineItemType;
private String name;
private String externalId;
private String comments;
private String orderId;
@JsonSerialize(using = AmazonJsonDateTimeSerializer.class)
private LocalDateTime startDateTime;
@JsonSerialize(using = AmazonJsonDateTimeSerializer.class)
private LocalDateTime endDateTime;
private DeliveryActivationStatus deliveryActivationStatus;
private LineItemDeliveryStatus deliveryStatus;
private LineItemClassification lineItemClassification;
private CurrencyCode currencyCode;
private AppliedFees appliedFees;
private Bidding bidding;
private LineItemTargeting targeting;
private LineItemBudget budget;
private FrequencyCap frequencyCap;
private LineItemOptimization optimization;
private CreativeOptions creativeOptions;
@JsonSerialize(using = AmazonJsonDateTimeSerializer.class)
private LocalDateTime creationDate;
@JsonSerialize(using = AmazonJsonDateTimeSerializer.class)
private LocalDateTime lastUpdatedDate;
private AmazonLineItem(Builder builder) {
lineItemId = builder.lineItemId;
lineItemType = builder.lineItemType;
name = builder.name;
externalId = builder.externalId;
comments = builder.comments;
orderId = builder.orderId;
startDateTime = builder.startDateTime;
endDateTime = builder.endDateTime;
deliveryActivationStatus = builder.deliveryActivationStatus;
deliveryStatus = builder.deliveryStatus;
lineItemClassification = builder.lineItemClassification;
currencyCode = builder.currencyCode;
appliedFees = builder.appliedFees;
bidding = builder.bidding;
targeting = builder.targeting;
budget = builder.budget;
frequencyCap = builder.frequencyCap;
optimization = builder.optimization;
creativeOptions = builder.creativeOptions;
creationDate = builder.creationDate;
lastUpdatedDate = builder.lastUpdatedDate;
}
public String getLineItemId() {
return lineItemId;
}
public LineItemType getLineItemType() {
return lineItemType;
}
public String getName() {
return name;
}
public String getExternalId() {
return externalId;
}
public String getComments() {
return comments;
}
public String getOrderId() {
return orderId;
}
public LocalDateTime getStartDateTime() {
return startDateTime;
}
public LocalDateTime getEndDateTime() {
return endDateTime;
}
public DeliveryActivationStatus getDeliveryActivationStatus() {
return deliveryActivationStatus;
}
public LineItemDeliveryStatus getDeliveryStatus() {
return deliveryStatus;
}
public LineItemClassification getLineItemClassification() {
return lineItemClassification;
}
public CurrencyCode getCurrencyCode() {
return currencyCode;
}
public AppliedFees getAppliedFees() {
return appliedFees;
}
public Bidding getBidding() {
return bidding;
}
public LineItemTargeting getTargeting() {
return targeting;
}
public LineItemBudget getBudget() {
return budget;
}
public FrequencyCap getFrequencyCap() {
return frequencyCap;
}
public LineItemOptimization getOptimization() {
return optimization;
}
public CreativeOptions getCreativeOptions() {
return creativeOptions;
}
public LocalDateTime getCreationDate() {
return creationDate;
}
public LocalDateTime getLastUpdatedDate() {
return lastUpdatedDate;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AmazonLineItem that = (AmazonLineItem) o;
return Objects.equals(lineItemId, that.lineItemId) &&
lineItemType == that.lineItemType &&
Objects.equals(name, that.name) &&
Objects.equals(externalId, that.externalId) &&
Objects.equals(comments, that.comments) &&
Objects.equals(orderId, that.orderId) &&
Objects.equals(startDateTime, that.startDateTime) &&
Objects.equals(endDateTime, that.endDateTime) &&
deliveryActivationStatus == that.deliveryActivationStatus &&
deliveryStatus == that.deliveryStatus &&
Objects.equals(lineItemClassification, that.lineItemClassification) &&
currencyCode == that.currencyCode &&
Objects.equals(appliedFees, that.appliedFees) &&
Objects.equals(bidding, that.bidding) &&
Objects.equals(targeting, that.targeting) &&
Objects.equals(budget, that.budget) &&
Objects.equals(frequencyCap, that.frequencyCap) &&
Objects.equals(optimization, that.optimization) &&
creativeOptions == that.creativeOptions &&
Objects.equals(creationDate, that.creationDate) &&
Objects.equals(lastUpdatedDate, that.lastUpdatedDate);
}
@Override
public int hashCode() {
return Objects.hash(lineItemId, lineItemType, name, externalId, comments, orderId, startDateTime, endDateTime, deliveryActivationStatus, deliveryStatus, lineItemClassification, currencyCode, appliedFees, bidding, targeting, budget, frequencyCap, optimization, creativeOptions, creationDate, lastUpdatedDate);
}
@JsonIgnoreProperties(ignoreUnknown = true)
public static final class Builder {
@JsonProperty("lineItemId")
private String lineItemId;
@JsonProperty("lineItemType")
private LineItemType lineItemType;
@JsonProperty("name")
private String name;
@JsonProperty("externalId")
private String externalId;
@JsonProperty("comments")
private String comments;
@JsonProperty("orderId")
private String orderId;
@JsonProperty("startDateTime")
@JsonDeserialize(using = AmazonJsonDateTimeDeserializer.class)
private LocalDateTime startDateTime;
@JsonProperty("endDateTime")
@JsonDeserialize(using = AmazonJsonDateTimeDeserializer.class)
private LocalDateTime endDateTime;
@JsonProperty("deliveryActivationStatus")
private DeliveryActivationStatus deliveryActivationStatus;
@JsonProperty("deliveryStatus")
private LineItemDeliveryStatus deliveryStatus;
@JsonProperty("lineItemClassification")
private LineItemClassification lineItemClassification;
@JsonProperty("currencyCode")
private CurrencyCode currencyCode;
@JsonProperty("appliedFees")
private AppliedFees appliedFees;
@JsonProperty("bidding")
private Bidding bidding;
@JsonProperty("targeting")
private LineItemTargeting targeting;
@JsonProperty("budget")
private LineItemBudget budget;
@JsonProperty("frequencyCap")
private FrequencyCap frequencyCap;
@JsonProperty("optimization")
private LineItemOptimization optimization;
@JsonProperty("creativeOptions")
private CreativeOptions creativeOptions;
@JsonProperty("creationDate")
@JsonDeserialize(using = AmazonJsonDateTimeDeserializer.class)
private LocalDateTime creationDate;
@JsonProperty("lastUpdatedDate")
@JsonDeserialize(using = AmazonJsonDateTimeDeserializer.class)
private LocalDateTime lastUpdatedDate;
public Builder() {
}
public Builder(AmazonLineItem copy) {
this.lineItemId = copy.getLineItemId();
this.lineItemType = copy.getLineItemType();
this.name = copy.getName();
this.externalId = copy.getExternalId();
this.comments = copy.getComments();
this.orderId = copy.getOrderId();
this.startDateTime = copy.getStartDateTime();
this.endDateTime = copy.getEndDateTime();
this.deliveryActivationStatus = copy.getDeliveryActivationStatus();
this.lineItemClassification = copy.getLineItemClassification();
this.deliveryStatus = copy.getDeliveryStatus();
this.currencyCode = copy.getCurrencyCode();
this.appliedFees = copy.getAppliedFees();
this.bidding = copy.getBidding();
this.targeting = copy.getTargeting();
this.budget = copy.getBudget();
this.frequencyCap = copy.getFrequencyCap();
this.optimization = copy.getOptimization();
this.creativeOptions = copy.getCreativeOptions();
this.creationDate = copy.getCreationDate();
this.lastUpdatedDate = copy.getLastUpdatedDate();
}
public Builder withLineItemId(String lineItemId) {
this.lineItemId = lineItemId;
return this;
}
public Builder withLineItemType(LineItemType lineItemType) {
this.lineItemType = lineItemType;
return this;
}
public Builder withName(String name) {
this.name = name;
return this;
}
public Builder withExternalId(String externalId) {
this.externalId = externalId;
return this;
}
public Builder withComments(String comments) {
this.comments = comments;
return this;
}
public Builder withOrderId(String orderId) {
this.orderId = orderId;
return this;
}
public Builder withStartDateTime(LocalDateTime startDateTime) {
this.startDateTime = startDateTime;
return this;
}
public Builder withEndDateTime(LocalDateTime endDateTime) {
this.endDateTime = endDateTime;
return this;
}
public Builder withDeliveryActivationStatus(DeliveryActivationStatus deliveryActivationStatus) {
this.deliveryActivationStatus = deliveryActivationStatus;
return this;
}
public Builder withLineItemClassification(LineItemClassification lineItemClassification) {
this.lineItemClassification = lineItemClassification;
return this;
}
public Builder withDeliveryStatus(LineItemDeliveryStatus deliveryStatus) {
this.deliveryStatus = deliveryStatus;
return this;
}
public Builder withCurrencyCode(CurrencyCode currencyCode) {
this.currencyCode = currencyCode;
return this;
}
public Builder withAppliedFees(AppliedFees appliedFees) {
this.appliedFees = appliedFees;
return this;
}
public Builder withBidding(Bidding bidding) {
this.bidding = bidding;
return this;
}
public Builder withBudget(LineItemBudget budget) {
this.budget = budget;
return this;
}
public Builder withTargeting(LineItemTargeting targeting) {
this.targeting = targeting;
return this;
}
public Builder withFrequencyCap(FrequencyCap frequencyCap) {
this.frequencyCap = frequencyCap;
return this;
}
public Builder withOptimization(LineItemOptimization optimization) {
this.optimization = optimization;
return this;
}
public Builder withCreativeOptions(CreativeOptions creativeOptions) {
this.creativeOptions = creativeOptions;
return this;
}
public Builder withCreationDate(LocalDateTime creationDate) {
this.creationDate = creationDate;
return this;
}
public Builder withLastUpdatedDate(LocalDateTime lastUpdatedDate) {
this.lastUpdatedDate = lastUpdatedDate;
return this;
}
public AmazonLineItem build() {
return new AmazonLineItem(this);
}
}
}
1
Make sure annotation processing is enabled
Preferences | Build, Execution, Deployment | Compiler | Annotation Processors
Enable annotation processing box is checkedObtain processors from project classpath option is selected
2
Install The Plugin
"Lombok Plugin by Michail Plushnikov"
3
Add dependency to Compile Classpath
compileOnly libs.lombok
annotationProcessor libs.lombok
5
Create lombok.config file
4
Don`t forget about tests
testCompileOnly testLibs.lombok testAnnotationProcessor testLibs.lombok
@Data
@Getter
@Setter
@RequiredArgsConstructor
@ToString
@EqualsAndHashCode
Mutable Classes
}
@Value
final class
@ToString
@EqualsAndHashCode
@AllArgsConstructor
@FieldDefaults(makeFinal = true,
level = AccessLevel.PRIVATE)
@Getter
Immutable Classes
}
Record | Lombok
record Person(String name, int age) { }
# CODE EXAMPLE
import lombok.Value;
@Value
public class Person {
String name;
int age;
}
- A private final field for each component
- A public constructor, with the same arguments as the components
- Public getter methods for each component (named after the component)
- equals(), hashCode(), and toString() methods
Code
By viktoriia2892
Code
- 6