@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user