Delombok code.

Closes #2286
This commit is contained in:
Mark Paluch
2023-07-07 14:51:03 +02:00
parent 18030f9171
commit aa7262b038
38 changed files with 989 additions and 231 deletions

View File

@@ -1,2 +0,0 @@
lombok.nonNull.exceptionType = IllegalArgumentException
lombok.log.fieldName = LOG

View File

@@ -133,7 +133,6 @@
<version>${hamcrest}</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>

View File

@@ -18,8 +18,6 @@ package org.springframework.data.rest.core;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import lombok.Value;
import java.net.URI;
import java.util.List;
import java.util.Optional;
@@ -49,6 +47,7 @@ import org.springframework.data.rest.core.UriToEntityConverterUnitTests.JMolecul
import org.springframework.data.util.Streamable;
import org.springframework.data.util.TypeInformation;
import org.springframework.format.support.DefaultFormattingConversionService;
import org.springframework.util.ObjectUtils;
/**
* Unit tests for {@link UriToEntityConverter}.
@@ -197,9 +196,37 @@ class UriToEntityConverterUnitTests {
return JMoleculesIdentifier.of(UUID.randomUUID());
}
@Value(staticConstructor = "of")
static class JMoleculesIdentifier implements Identifier {
UUID id;
static final class JMoleculesIdentifier implements Identifier {
private final UUID id;
private JMoleculesIdentifier(UUID id) {
this.id = id;
}
public static JMoleculesIdentifier of(UUID id) {
return new JMoleculesIdentifier(id);
}
public UUID getId() {
return this.id;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
JMoleculesIdentifier that = (JMoleculesIdentifier) o;
return ObjectUtils.nullSafeEquals(id, that.id);
}
@Override
public int hashCode() {
return ObjectUtils.nullSafeHashCode(id);
}
}
}

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.rest.core.domain;
import lombok.Value;
import java.util.UUID;
import org.springframework.data.annotation.Id;
@@ -25,9 +23,20 @@ import org.springframework.data.annotation.Reference;
/**
* @author Oliver Gierke
*/
@Value
class Order {
final class Order {
@Id UUID id = UUID.randomUUID();
@Reference Person creator;
@Id private final UUID id = UUID.randomUUID();
@Reference private final Person creator;
public Order(Person creator) {
this.creator = creator;
}
public UUID getId() {
return this.id;
}
public Person getCreator() {
return this.creator;
}
}

View File

@@ -15,10 +15,6 @@
*/
package org.springframework.data.rest.core.domain;
import lombok.AccessLevel;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@@ -26,7 +22,7 @@ import java.util.List;
import java.util.UUID;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.annotation.PersistenceCreator;
import org.springframework.data.annotation.Reference;
import org.springframework.data.rest.core.annotation.RestResource;
@@ -36,8 +32,6 @@ import org.springframework.data.rest.core.annotation.RestResource;
* @author Jon Brisbin
* @author Oliver Gierke
*/
@Data
@RequiredArgsConstructor(access = AccessLevel.PRIVATE, onConstructor = @__(@PersistenceConstructor))
public class Person {
private final @Id UUID id;
@@ -51,8 +45,51 @@ public class Person {
private @RestResource(path = "father-mapped") @Reference Person father;
private Date created = Calendar.getInstance().getTime();
@PersistenceCreator
private Person(UUID id, String firstName, String lastName) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
}
public Person addSibling(Person p) {
siblings.add(p);
return this;
}
public UUID getId() {
return this.id;
}
public String getFirstName() {
return this.firstName;
}
public String getLastName() {
return this.lastName;
}
public List<Person> getSiblings() {
return this.siblings;
}
public Person getFather() {
return this.father;
}
public Date getCreated() {
return this.created;
}
public void setSiblings(List<Person> siblings) {
this.siblings = siblings;
}
public void setFather(Person father) {
this.father = father;
}
public void setCreated(Date created) {
this.created = created;
}
}

View File

@@ -15,9 +15,6 @@
*/
package org.springframework.data.rest.core.domain;
import lombok.Value;
import lombok.experimental.NonFinal;
import java.util.UUID;
import org.springframework.data.annotation.Id;
@@ -26,10 +23,25 @@ import org.springframework.data.annotation.Id;
* @author Jon Brisbin
* @author Oliver Gierke
*/
@NonFinal
@Value
public class Profile {
@Id UUID id = UUID.randomUUID();
String name, type;
@Id private final UUID id = UUID.randomUUID();
private final String name, type;
public Profile(String name, String type) {
this.name = name;
this.type = type;
}
public UUID getId() {
return this.id;
}
public String getName() {
return this.name;
}
public String getType() {
return this.type;
}
}

View File

@@ -17,8 +17,6 @@ package org.springframework.data.rest.core.support;
import static org.assertj.core.api.Assertions.*;
import lombok.Value;
import java.util.stream.Stream;
import org.junit.jupiter.api.DynamicTest;
@@ -34,36 +32,31 @@ class ResourceStringUtilsTests {
@TestFactory
Stream<DynamicTest> shouldDetectTextPresence() {
return DynamicTest.stream(fixtures(), Fixture::getName, it -> {
assertThat(ResourceStringUtils.hasTextExceptSlash(it.getActual())).isEqualTo(it.hasText);
return DynamicTest.stream(fixtures(), Fixture::name, it -> {
assertThat(ResourceStringUtils.hasTextExceptSlash(it.actual())).isEqualTo(it.hasText);
});
}
@TestFactory
Stream<DynamicTest> shouldRemoveLeadingSlashIfAny() {
return DynamicTest.stream(fixtures(), Fixture::getName, it -> {
assertThat(ResourceStringUtils.removeLeadingSlash(it.getActual())).isEqualTo(it.getExpected());
return DynamicTest.stream(fixtures(), Fixture::name, it -> {
assertThat(ResourceStringUtils.removeLeadingSlash(it.actual())).isEqualTo(it.expected());
});
}
static Stream<Fixture> fixtures() {
return Stream.of(
Fixture.of("empty string has no text and should remain empty", "", "", false),
Fixture.of("blank string has no text and should remain as is", " ", " ", false),
Fixture.of("string made of only a leading slash has no text and should be returned empty", "/", "", false),
Fixture.of("blank string with only slashes has no text and should be returned as is", " / ", " / ",
return Stream.of(new Fixture("empty string has no text and should remain empty", "", "", false),
new Fixture("blank string has no text and should remain as is", " ", " ", false),
new Fixture("string made of only a leading slash has no text and should be returned empty", "/", "", false),
new Fixture("blank string with only slashes has no text and should be returned as is", " / ", " / ",
false),
Fixture.of("normal string has text and should be returned as such", "hello", "hello", true),
Fixture.of("normal string with leading slash has text and should be returned without leading slash", "/hello",
new Fixture("normal string has text and should be returned as such", "hello", "hello", true),
new Fixture("normal string with leading slash has text and should be returned without leading slash", "/hello",
"hello", true));
}
@Value(staticConstructor = "of")
static class Fixture {
String name, actual, expected;
boolean hasText;
record Fixture(String name, String actual, String expected, boolean hasText) {
}
}

View File

@@ -39,13 +39,6 @@
<version>${groovy.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -21,9 +21,6 @@ import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToMany;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.util.HashSet;
import java.util.Set;
@@ -68,13 +65,33 @@ public class Book {
this.offer = offer;
}
@Getter
@Embeddable
@AllArgsConstructor
@NoArgsConstructor
static class Offer {
double price;
String currency;
public Offer(double price, String currency) {
this.price = price;
this.currency = currency;
}
public Offer() {}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getCurrency() {
return currency;
}
public void setCurrency(String currency) {
this.currency = currency;
}
}
}

View File

@@ -19,12 +19,10 @@ import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Version;
import lombok.Data;
/**
* @author Dario Seidl
*/
@Data
@Entity
class Category {
@@ -38,4 +36,28 @@ class Category {
public Category(String name) {
this.name = name;
}
public Long getId() {
return this.id;
}
public Long getVersion() {
return this.version;
}
public String getName() {
return this.name;
}
public void setId(Long id) {
this.id = id;
}
public void setVersion(Long version) {
this.version = version;
}
public void setName(String name) {
this.name = name;
}
}

View File

@@ -18,10 +18,6 @@ package org.springframework.data.rest.webmvc.jpa;
import jakarta.persistence.Embeddable;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
@@ -29,19 +25,35 @@ import com.fasterxml.jackson.annotation.JsonUnwrapped;
* @author Oliver Gierke
*/
@Entity
@Getter
@NoArgsConstructor(force = true)
@RequiredArgsConstructor
public class CreditCard {
@Id Long id;
final @JsonUnwrapped CCN ccn;
public CreditCard(CCN ccn) {
this.ccn = ccn;
}
public Long getId() {
return this.id;
}
public CCN getCcn() {
return this.ccn;
}
@Embeddable
@Getter
@NoArgsConstructor(force = true)
@AllArgsConstructor
public static class CCN {
String ccn;
public CCN(String ccn) {
this.ccn = ccn;
}
public CCN() {}
public String getCcn() {
return this.ccn;
}
}
}

View File

@@ -17,12 +17,10 @@ package org.springframework.data.rest.webmvc.jpa;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import lombok.Data;
/**
* @author Alex Leigh
*/
@Data
@Entity
@DiscriminatorValue("D")
public class Dinner extends Meal {
@@ -35,4 +33,12 @@ public class Dinner extends Meal {
public String getType() {
return TYPE;
}
public String getDinnerCode() {
return this.dinnerCode;
}
public void setDinnerCode(String dinnerCode) {
this.dinnerCode = dinnerCode;
}
}

View File

@@ -21,7 +21,6 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@@ -29,7 +28,6 @@ import java.util.List;
/**
* @author Alex Leigh
*/
@Data
@Entity
public class Guest {
@@ -45,4 +43,28 @@ public class Guest {
public void addMeal(Meal meal) {
this.meals.add(meal);
}
public Long getId() {
return this.id;
}
public Room getRoom() {
return this.room;
}
public List<Meal> getMeals() {
return this.meals;
}
public void setId(Long id) {
this.id = id;
}
public void setRoom(Room room) {
this.room = room;
}
public void setMeals(List<Meal> meals) {
this.meals = meals;
}
}

View File

@@ -19,7 +19,6 @@ import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
@@ -27,7 +26,6 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
/**
* @author Alex Leigh
*/
@Data
@Entity
@Inheritance
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type")
@@ -37,4 +35,12 @@ public abstract class Meal {
@Id @GeneratedValue private Long id;
public abstract String getType();
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
}

View File

@@ -20,7 +20,6 @@ import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
@@ -28,7 +27,6 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
/**
* @author Alex Leigh
*/
@Data
@Entity
@Inheritance
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type")
@@ -39,4 +37,12 @@ public abstract class Room {
private Long id;
public abstract String getType();
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
}

View File

@@ -17,12 +17,10 @@ package org.springframework.data.rest.webmvc.jpa;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import lombok.Data;
/**
* @author Alex Leigh
*/
@Data
@Entity
@DiscriminatorValue("S")
public class Suite extends Room {
@@ -35,4 +33,12 @@ public class Suite extends Room {
public String getType() {
return TYPE;
}
public String getSuiteCode() {
return this.suiteCode;
}
public void setSuiteCode(String suiteCode) {
this.suiteCode = suiteCode;
}
}

View File

@@ -36,7 +36,7 @@
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.9.0</version>
<version>4.10.1</version>
</dependency>
<dependency>

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.rest.tests.mongodb;
import lombok.Value;
import java.math.BigInteger;
import java.time.LocalDateTime;
import java.util.HashMap;
@@ -74,9 +72,21 @@ public class User {
public static class TypeWithPattern {}
@Value
public static class Nested {
public @DBRef(lazy = true) User user;
public String foo = "foo";
public static final class Nested {
public final @DBRef(lazy = true) User user;
public final String foo = "foo";
public Nested(User user) {
this.user = user;
}
public User getUser() {
return this.user;
}
public String getFoo() {
return this.foo;
}
}
}

View File

@@ -19,8 +19,6 @@ import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.rest.tests.mongodb.TestUtils.*;
import lombok.Data;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -178,12 +176,43 @@ class JsonPatchHandlerUnitTests {
}
@JsonIgnoreProperties("password")
@Data
static class WithIgnoredProperties {
String name, lastname, password;
@JsonIgnore String ssn;
public String getName() {
return this.name;
}
public String getLastname() {
return this.lastname;
}
public String getPassword() {
return this.password;
}
public String getSsn() {
return this.ssn;
}
public void setName(String name) {
this.name = name;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public void setPassword(String password) {
this.password = password;
}
@JsonIgnore
public void setSsn(String ssn) {
this.ssn = ssn;
}
}
}

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.rest.tests.security;
import lombok.Value;
import java.util.UUID;
import org.springframework.data.annotation.Id;
@@ -24,9 +22,21 @@ import org.springframework.data.annotation.Id;
/**
* @author Oliver Gierke
*/
@Value
public class Order {
public final class Order {
@Id private final UUID id = UUID.randomUUID();
private final Person customer;
public Order(Person customer) {
this.customer = customer;
}
public UUID getId() {
return this.id;
}
public Person getCustomer() {
return this.customer;
}
@Id UUID id = UUID.randomUUID();
Person customer;
}

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.rest.tests.security;
import lombok.Value;
import java.util.UUID;
import org.springframework.data.annotation.Id;
@@ -24,9 +22,26 @@ import org.springframework.data.annotation.Id;
/**
* @author Oliver Gierke
*/
@Value
public class Person {
public final class Person {
@Id private final UUID id = UUID.randomUUID();
private final String firstname, lastname;
public Person(String firstname, String lastname) {
this.firstname = firstname;
this.lastname = lastname;
}
public UUID getId() {
return this.id;
}
public String getFirstname() {
return this.firstname;
}
public String getLastname() {
return this.lastname;
}
@Id UUID id = UUID.randomUUID();
String firstname, lastname;
}

View File

@@ -15,9 +15,6 @@
*/
package org.springframework.data.rest.tests.shop;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import java.util.UUID;
import org.springframework.data.annotation.Id;
@@ -25,14 +22,43 @@ import org.springframework.data.annotation.Id;
/**
* @author Oliver Gierke
*/
@Data
@RequiredArgsConstructor
public class Address {
private @Id UUID id = UUID.randomUUID();
private final String street, zipCode, city, state;
public Address(String street, String zipCode, String city, String state) {
this.street = street;
this.zipCode = zipCode;
this.city = city;
this.state = state;
}
public String toString() {
return String.format("%s, %s %s, %s", street, zipCode, city, state);
}
public UUID getId() {
return this.id;
}
public String getStreet() {
return this.street;
}
public String getZipCode() {
return this.zipCode;
}
public String getCity() {
return this.city;
}
public String getState() {
return this.state;
}
public void setId(UUID id) {
this.id = id;
}
}

View File

@@ -15,9 +15,6 @@
*/
package org.springframework.data.rest.tests.shop;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import java.util.UUID;
import org.springframework.data.annotation.Id;
@@ -25,8 +22,6 @@ import org.springframework.data.annotation.Id;
/**
* @author Oliver Gierke
*/
@Data
@RequiredArgsConstructor
public class Customer {
private final @Id UUID id = UUID.randomUUID();
@@ -34,6 +29,33 @@ public class Customer {
private final Gender gender;
private final Address address;
public Customer(String firstname, String lastname, Gender gender, Address address) {
this.firstname = firstname;
this.lastname = lastname;
this.gender = gender;
this.address = address;
}
public UUID getId() {
return this.id;
}
public String getFirstname() {
return this.firstname;
}
public String getLastname() {
return this.lastname;
}
public Gender getGender() {
return this.gender;
}
public Address getAddress() {
return this.address;
}
static enum Gender {
MALE, FEMALE;
}

View File

@@ -15,9 +15,6 @@
*/
package org.springframework.data.rest.tests.shop;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
@@ -27,20 +24,14 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Reference;
import org.springframework.data.rest.core.config.Projection;
import org.springframework.data.rest.tests.shop.Product.ProductNameOnlyProjection;
import org.springframework.util.ObjectUtils;
/**
* @author Oliver Gierke
* @author Craig Andrews
*/
@Data
@EqualsAndHashCode(of = "id")
public class LineItem {
@Projection(name = "productsOnly", types = LineItem.class)
public interface LineItemProductsOnlyProjection {
List<ProductNameOnlyProjection> getProducts();
}
private final @Id UUID id = UUID.randomUUID();
private final String description;
private final BigDecimal price;
@@ -62,4 +53,54 @@ public class LineItem {
this.product = product;
this.products = Arrays.asList(product, product);
}
public UUID getId() {
return this.id;
}
public String getDescription() {
return this.description;
}
public BigDecimal getPrice() {
return this.price;
}
public Product getProduct() {
return this.product;
}
public List<Product> getProducts() {
return this.products;
}
public LineItemType getType() {
return this.type;
}
public List<LineItemType> getTypes() {
return this.types;
}
@Projection(name = "productsOnly", types = LineItem.class)
public interface LineItemProductsOnlyProjection {
List<ProductNameOnlyProjection> getProducts();
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
LineItem lineItem = (LineItem) o;
return ObjectUtils.nullSafeEquals(id, lineItem.id);
}
@Override
public int hashCode() {
return ObjectUtils.nullSafeHashCode(id);
}
}

View File

@@ -15,24 +15,45 @@
*/
package org.springframework.data.rest.tests.shop;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import java.util.UUID;
import org.springframework.data.annotation.Id;
import org.springframework.util.ObjectUtils;
/**
* @author Oliver Gierke
*/
@Getter
@EqualsAndHashCode(of = "id")
@ToString
@RequiredArgsConstructor
public class LineItemType {
private final @Id UUID id = UUID.randomUUID();
private final String name;
public LineItemType(String name) {
this.name = name;
}
public UUID getId() {
return this.id;
}
public String getName() {
return this.name;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
LineItemType that = (LineItemType) o;
return ObjectUtils.nullSafeEquals(id, that.id);
}
@Override
public int hashCode() {
return ObjectUtils.nullSafeHashCode(id);
}
}

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.rest.tests.shop;
import lombok.Value;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@@ -29,32 +27,106 @@ import org.springframework.data.annotation.Reference;
import org.springframework.data.rest.core.config.Projection;
import org.springframework.data.rest.tests.shop.LineItem.LineItemProductsOnlyProjection;
import org.springframework.data.rest.tests.shop.Order.OrderIdentifier;
import org.springframework.util.ObjectUtils;
/**
* @author Oliver Gierke
* @author Craig Andrews
*/
@Value
public class Order implements AggregateRoot<Order, OrderIdentifier> {
@Projection(name = "itemsOnly", types = Order.class)
public interface OrderItemsOnlyProjection {
List<LineItemProductsOnlyProjection> getItems();
}
public final class Order implements AggregateRoot<Order, OrderIdentifier> {
private final @Id OrderIdentifier id = new OrderIdentifier(UUID.randomUUID());
private final List<LineItem> items = new ArrayList<>();
private final @Reference Customer customer;
public Order(Customer customer) {
this.customer = customer;
}
public OrderIdentifier getId() {
return this.id;
}
public List<LineItem> getItems() {
return this.items;
}
public Customer getCustomer() {
return this.customer;
}
public Order add(LineItem item) {
this.items.add(item);
return this;
}
@Value
static class OrderIdentifier implements Identifier, Serializable {
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Order order = (Order) o;
if (!ObjectUtils.nullSafeEquals(id, order.id)) {
return false;
}
if (!ObjectUtils.nullSafeEquals(items, order.items)) {
return false;
}
return ObjectUtils.nullSafeEquals(customer, order.customer);
}
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(id);
result = 31 * result + ObjectUtils.nullSafeHashCode(items);
result = 31 * result + ObjectUtils.nullSafeHashCode(customer);
return result;
}
@Projection(name = "itemsOnly", types = Order.class)
public interface OrderItemsOnlyProjection {
List<LineItemProductsOnlyProjection> getItems();
}
static final class OrderIdentifier implements Identifier, Serializable {
private static final long serialVersionUID = -3362660123468974881L;
UUID id;
private final UUID id;
public OrderIdentifier(UUID id) {
this.id = id;
}
public UUID getId() {
return this.id;
}
public boolean equals(final Object o) {
if (o == this)
return true;
if (!(o instanceof OrderIdentifier))
return false;
final OrderIdentifier other = (OrderIdentifier) o;
final Object this$id = this.getId();
final Object other$id = other.getId();
if (this$id == null ? other$id != null : !this$id.equals(other$id))
return false;
return true;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $id = this.getId();
result = result * PRIME + ($id == null ? 43 : $id.hashCode());
return result;
}
public String toString() {
return "Order.OrderIdentifier(id=" + this.getId() + ")";
}
}
}

View File

@@ -15,31 +15,73 @@
*/
package org.springframework.data.rest.tests.shop;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import lombok.experimental.NonFinal;
import java.math.BigDecimal;
import java.util.UUID;
import org.springframework.data.annotation.Id;
import org.springframework.data.rest.core.config.Projection;
import org.springframework.util.ObjectUtils;
/**
* @author Oliver Gierke
* @author Craig Andrews
*/
@NonFinal
@Value
@RequiredArgsConstructor
public class Product {
private final @Id UUID id = UUID.randomUUID();
private final String name;
private final BigDecimal price;
public Product(String name, BigDecimal price) {
this.name = name;
this.price = price;
}
public UUID getId() {
return this.id;
}
public String getName() {
return this.name;
}
public BigDecimal getPrice() {
return this.price;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Product product = (Product) o;
if (!ObjectUtils.nullSafeEquals(id, product.id)) {
return false;
}
if (!ObjectUtils.nullSafeEquals(name, product.name)) {
return false;
}
return ObjectUtils.nullSafeEquals(price, product.price);
}
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(id);
result = 31 * result + ObjectUtils.nullSafeHashCode(name);
result = 31 * result + ObjectUtils.nullSafeHashCode(price);
return result;
}
public String toString() {
return "Product(id=" + this.getId() + ", name=" + this.getName() + ", price=" + this.getPrice() + ")";
}
@Projection(name = "nameOnly", types = Product.class)
public interface ProductNameOnlyProjection {
String getName();
}
private final @Id UUID id = UUID.randomUUID();
private final String name;
private final BigDecimal price;
}

View File

@@ -49,13 +49,6 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok}</version>
<optional>true</optional>
</dependency>
<!-- Jackson -->
<dependency>

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.rest.webmvc.config;
import lombok.SneakyThrows;
import java.util.Arrays;
import java.util.List;
@@ -55,7 +53,6 @@ class HalFormsAdaptingResponseBodyAdvice<T extends RepresentationModel<T>>
}
@Override
@SneakyThrows
public RepresentationModel<T> beforeBodyWrite(@Nullable RepresentationModel<T> body, MethodParameter returnType,
MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType,
ServerHttpRequest request, ServerHttpResponse response) {
@@ -67,8 +64,7 @@ class HalFormsAdaptingResponseBodyAdvice<T extends RepresentationModel<T>>
List<MediaType> accept = request.getHeaders().getAccept();
boolean hasAffordances = body != null && body.getLinks().stream()
.anyMatch(it -> !it.getAffordances().isEmpty());
boolean hasAffordances = body != null && body.getLinks().stream().anyMatch(it -> !it.getAffordances().isEmpty());
// Affordances registered -> we're fine as we will render templates
if (hasAffordances) {
@@ -90,6 +86,13 @@ class HalFormsAdaptingResponseBodyAdvice<T extends RepresentationModel<T>>
}
// Reject the request otherwise
throw new HttpMediaTypeNotAcceptableException(SUPPORTED_MEDIA_TYPES);
HalFormsAdaptingResponseBodyAdvice.throwException(new HttpMediaTypeNotAcceptableException(SUPPORTED_MEDIA_TYPES));
throw new UnsupportedOperationException();
}
@SuppressWarnings("unchecked")
private static <T extends Throwable> void throwException(Throwable exception) throws T {
throw (T) exception;
}
}

View File

@@ -15,8 +15,6 @@
*/
package org.springframework.data.rest.webmvc.json.patch;
import lombok.RequiredArgsConstructor;
import java.util.Optional;
import java.util.function.BiFunction;
@@ -29,7 +27,6 @@ import org.springframework.util.StringUtils;
/**
* @author Oliver Drotbohm
*/
@RequiredArgsConstructor
class JsonPointerMapping {
private final BiFunction<String, Class<?>, Optional<String>> reader, writer;
@@ -40,6 +37,12 @@ class JsonPointerMapping {
this.writer = context::getWritableProperty;
}
public JsonPointerMapping(BiFunction<String, Class<?>, Optional<String>> reader,
BiFunction<String, Class<?>, Optional<String>> writer) {
this.reader = reader;
this.writer = writer;
}
/**
* Maps the given JSON Pointer to the given type to ultimately read the attribute pointed to.
*

View File

@@ -19,8 +19,6 @@ import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import lombok.Value;
import java.util.Date;
import java.util.function.Supplier;
@@ -114,8 +112,16 @@ class ResourceStatusUnitTests {
assertThat(statusAndHeaders.toResponseEntity(supplier).getStatusCode()).isEqualTo(HttpStatus.NOT_MODIFIED);
}
@Value
static class Sample {
@Version int version;
static final class Sample {
@Version private final int version;
public Sample(int version) {
this.version = version;
}
public int getVersion() {
return this.version;
}
}
}

View File

@@ -19,13 +19,6 @@ import static com.fasterxml.jackson.annotation.JsonProperty.Access.*;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -50,6 +43,7 @@ import org.springframework.data.mapping.context.PersistentEntities;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.core.mapping.ResourceMappings;
import org.springframework.data.rest.webmvc.mapping.Associations;
import org.springframework.util.ObjectUtils;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
@@ -797,10 +791,14 @@ class DomainObjectReaderUnitTests {
}
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
@NoArgsConstructor
@AllArgsConstructor
static class Item {
String some;
public Item(String some) {
this.some = some;
}
public Item() {}
}
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
@@ -809,11 +807,41 @@ class DomainObjectReaderUnitTests {
}
@JsonAutoDetect(fieldVisibility = Visibility.ANY)
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
static class LocalizedValue {
String value;
public LocalizedValue(String value) {
this.value = value;
}
public LocalizedValue() {}
public boolean equals(final Object o) {
if (o == this)
return true;
if (!(o instanceof LocalizedValue))
return false;
final LocalizedValue other = (LocalizedValue) o;
if (!other.canEqual((Object) this))
return false;
final Object this$value = this.value;
final Object other$value = other.value;
if (this$value == null ? other$value != null : !this$value.equals(other$value))
return false;
return true;
}
protected boolean canEqual(final Object other) {
return other instanceof LocalizedValue;
}
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $value = this.value;
result = result * PRIME + ($value == null ? 43 : $value.hashCode());
return result;
}
}
@JsonAutoDetect(getterVisibility = Visibility.ANY)
@@ -833,7 +861,7 @@ class DomainObjectReaderUnitTests {
String getFoo();
}
static enum SampleEnum implements EnumInterface {
enum SampleEnum implements EnumInterface {
FIRST {
@@ -856,16 +884,51 @@ class DomainObjectReaderUnitTests {
List<SampleEnum> enums = new ArrayList<SampleEnum>();
}
@EqualsAndHashCode
@AllArgsConstructor
static class SampleWithReference {
private @Getter @Reference List<Nested> nested;
private @Reference List<Nested> nested;
public SampleWithReference(List<Nested> nested) {
this.nested = nested;
}
public List<Nested> getNested() {
return this.nested;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
SampleWithReference that = (SampleWithReference) o;
return ObjectUtils.nullSafeEquals(nested, that.nested);
}
@Override
public int hashCode() {
return ObjectUtils.nullSafeHashCode(nested);
}
}
@Immutable
@Value
static class Nested {
int x, y;
static final class Nested {
private final int x, y;
public Nested(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
}
// DATAREST-1030
@@ -882,11 +945,14 @@ class DomainObjectReaderUnitTests {
String name;
}
@RequiredArgsConstructor
static class SelectValueByIdSerializer<T> extends JsonDeserializer<T> {
private final Map<? extends Object, T> values;
public SelectValueByIdSerializer(Map<? extends Object, T> values) {
this.values = values;
}
@Override
public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
@@ -907,9 +973,17 @@ class DomainObjectReaderUnitTests {
}
// DATAREST-1068
@Value
static class ArrayHolder {
String[] array;
static final class ArrayHolder {
private final String[] array;
ArrayHolder(String[] array) {
this.array = array;
}
public String[] getArray() {
return array;
}
}
// DATAREST-1026

View File

@@ -19,9 +19,6 @@ import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import lombok.Data;
import lombok.Getter;
import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
@@ -289,7 +286,6 @@ class PersistentEntityJackson2ModuleUnitTests {
}
}
@Getter
@JsonInclude(Include.NON_NULL)
static class PetOwner {
@@ -297,6 +293,18 @@ class PersistentEntityJackson2ModuleUnitTests {
Home home;
@JsonProperty("package") Package _package;
public Pet getPet() {
return this.pet;
}
public Home getHome() {
return this.home;
}
public Package get_package() {
return this._package;
}
}
static class Package {}
@@ -330,9 +338,16 @@ class PersistentEntityJackson2ModuleUnitTests {
// GH-1926
@Data
static class Wrapper {
ValueType value;
public ValueType getValue() {
return this.value;
}
public void setValue(ValueType value) {
this.value = value;
}
}
static class ValueType {
@@ -341,9 +356,16 @@ class PersistentEntityJackson2ModuleUnitTests {
// GH-2056
@Data
static class Surrounding {
CustomType custom = new CustomType();
public CustomType getCustom() {
return this.custom;
}
public void setCustom(CustomType custom) {
this.custom = custom;
}
}
static class CustomType {}

View File

@@ -17,10 +17,6 @@ package org.springframework.data.rest.webmvc.json.patch;
import static org.assertj.core.api.Assertions.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.List;
@@ -159,10 +155,21 @@ class AddOperationUnitTests {
assertThat(outer.todoList.getTodos()).containsExactly(todos.get(0), todos.get(1), newTodo);
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class TodoListWrapper {
public TodoList todoList;
public TodoListWrapper(TodoList todoList) {
this.todoList = todoList;
}
public TodoListWrapper() {}
public TodoList getTodoList() {
return this.todoList;
}
public void setTodoList(TodoList todoList) {
this.todoList = todoList;
}
}
}

View File

@@ -17,9 +17,6 @@ package org.springframework.data.rest.webmvc.json.patch;
import static org.assertj.core.api.Assertions.*;
import lombok.Data;
import lombok.Getter;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
@@ -184,18 +181,75 @@ class SpelPathUnitTests {
// DATAREST-1338
@Data
static class Person {
String name;
@JsonIgnore String hiddenProperty;
@Getter(onMethod = @__(@JsonIgnore)) String hiddenGetter;
String hiddenGetter;
@JsonProperty("demaner") String renamed;
LocalDate birthday;
public String getName() {
return this.name;
}
public String getHiddenProperty() {
return this.hiddenProperty;
}
public String getRenamed() {
return this.renamed;
}
public LocalDate getBirthday() {
return this.birthday;
}
public void setName(String name) {
this.name = name;
}
@JsonIgnore
public void setHiddenProperty(String hiddenProperty) {
this.hiddenProperty = hiddenProperty;
}
public void setHiddenGetter(String hiddenGetter) {
this.hiddenGetter = hiddenGetter;
}
@JsonProperty("demaner")
public void setRenamed(String renamed) {
this.renamed = renamed;
}
public void setBirthday(LocalDate birthday) {
this.birthday = birthday;
}
@JsonIgnore
public String getHiddenGetter() {
return this.hiddenGetter;
}
}
@Data
static class MapWrapper {
Map<String, Person> people;
Map<Integer, Person> peopleByInt;
public Map<String, Person> getPeople() {
return this.people;
}
public Map<Integer, Person> getPeopleByInt() {
return this.peopleByInt;
}
public void setPeople(Map<String, Person> people) {
this.people = people;
}
public void setPeopleByInt(Map<Integer, Person> peopleByInt) {
this.peopleByInt = peopleByInt;
}
}
}

View File

@@ -16,21 +16,18 @@
package org.springframework.data.rest.webmvc.json.patch;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import org.springframework.util.ObjectUtils;
/**
* @author Roy Clarkson
* @author Craig Walls
* @author Mathias Düsterhöft
* @author Oliver Gierke
*/
@Data
@NoArgsConstructor
class Todo {
private Long id;
@@ -47,4 +44,103 @@ class Todo {
this.description = description;
this.complete = complete;
}
public Todo() {}
public Long getId() {
return this.id;
}
public String getDescription() {
return this.description;
}
public boolean isComplete() {
return this.complete;
}
public TodoType getType() {
return this.type;
}
public List<String> getItems() {
return this.items;
}
public List<String> getUninitialized() {
return this.uninitialized;
}
public BigInteger getAmount() {
return this.amount;
}
public void setId(Long id) {
this.id = id;
}
public void setDescription(String description) {
this.description = description;
}
public void setComplete(boolean complete) {
this.complete = complete;
}
public void setType(TodoType type) {
this.type = type;
}
public void setItems(List<String> items) {
this.items = items;
}
public void setUninitialized(List<String> uninitialized) {
this.uninitialized = uninitialized;
}
public void setAmount(BigInteger amount) {
this.amount = amount;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Todo todo = (Todo) o;
if (complete != todo.complete)
return false;
if (!ObjectUtils.nullSafeEquals(id, todo.id)) {
return false;
}
if (!ObjectUtils.nullSafeEquals(description, todo.description)) {
return false;
}
if (!ObjectUtils.nullSafeEquals(type, todo.type)) {
return false;
}
if (!ObjectUtils.nullSafeEquals(items, todo.items)) {
return false;
}
if (!ObjectUtils.nullSafeEquals(uninitialized, todo.uninitialized)) {
return false;
}
return ObjectUtils.nullSafeEquals(amount, todo.amount);
}
@Override
public int hashCode() {
int result = ObjectUtils.nullSafeHashCode(id);
result = 31 * result + ObjectUtils.nullSafeHashCode(description);
result = 31 * result + (complete ? 1 : 0);
result = 31 * result + ObjectUtils.nullSafeHashCode(type);
result = 31 * result + ObjectUtils.nullSafeHashCode(items);
result = 31 * result + ObjectUtils.nullSafeHashCode(uninitialized);
result = 31 * result + ObjectUtils.nullSafeHashCode(amount);
return result;
}
}

View File

@@ -15,12 +15,9 @@
*/
package org.springframework.data.rest.webmvc.json.patch;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
class TodoList implements Serializable {
private static final long serialVersionUID = 1L;
@@ -28,4 +25,28 @@ class TodoList implements Serializable {
private List<Todo> todos;
private Todo[] todoArray;
private String name;
public List<Todo> getTodos() {
return this.todos;
}
public Todo[] getTodoArray() {
return this.todoArray;
}
public String getName() {
return this.name;
}
public void setTodos(List<Todo> todos) {
this.todos = todos;
}
public void setTodoArray(Todo[] todoArray) {
this.todoArray = todoArray;
}
public void setName(String name) {
this.name = name;
}
}

View File

@@ -15,17 +15,43 @@
*/
package org.springframework.data.rest.webmvc.json.patch;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.ObjectUtils;
/**
* @author Mathias Düsterhöft
* @author Oliver Gierke
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
class TodoType {
private String value = "none";
public TodoType(String value) {
this.value = value;
}
public TodoType() {}
public String getValue() {
return this.value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
TodoType todoType = (TodoType) o;
return ObjectUtils.nullSafeEquals(value, todoType.value);
}
@Override
public int hashCode() {
return ObjectUtils.nullSafeHashCode(value);
}
}