Skip to content

Commit e7093ca

Browse files
committed
Adopt to changes in Spring Framework 7.
See #2449
1 parent 5cdc3cb commit e7093ca

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/DomainObjectReader.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.data.rest.webmvc.json;
1717

18+
import java.io.ByteArrayInputStream;
1819
import java.io.IOException;
1920
import java.io.InputStream;
2021
import java.util.ArrayList;
@@ -211,7 +212,8 @@ <T> T merge(ObjectNode source, T target, ObjectMapper mapper) {
211212
try {
212213
return doMerge(source, target, mapper);
213214
} catch (Exception o_O) {
214-
throw new HttpMessageNotReadableException("Could not read payload", o_O);
215+
throw new HttpMessageNotReadableException("Could not read payload", o_O,
216+
InputStreamHttpInputMessage.of(() -> new ByteArrayInputStream(mapper.writeValueAsBytes(source))));
215217
}
216218
}
217219

spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/util/InputStreamHttpInputMessage.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,43 @@
1616
package org.springframework.data.rest.webmvc.util;
1717

1818
import java.io.InputStream;
19+
import java.util.function.Supplier;
1920

2021
import org.springframework.http.HttpHeaders;
2122
import org.springframework.http.HttpInputMessage;
2223
import org.springframework.util.Assert;
24+
import org.springframework.util.function.ThrowingSupplier;
2325

2426
/**
2527
* {@link HttpInputMessage} based on a plain {@link InputStream}, i.e. exposing no headers.
2628
*
2729
* @author Oliver Drotbohm
30+
* @author Mark Paluch
2831
*/
2932
public class InputStreamHttpInputMessage implements HttpInputMessage {
3033

31-
private final InputStream body;
34+
private final Supplier<InputStream> body;
3235

33-
private InputStreamHttpInputMessage(final InputStream body) {
36+
private InputStreamHttpInputMessage(Supplier<InputStream> body) {
3437

3538
Assert.notNull(body, "InputStream must not be null");
3639

3740
this.body = body;
3841
}
3942

40-
public static InputStreamHttpInputMessage of(final InputStream body) {
43+
public static InputStreamHttpInputMessage of(InputStream body) {
44+
return new InputStreamHttpInputMessage(() -> body);
45+
}
46+
47+
/**
48+
* @since 5.0
49+
*/
50+
public static InputStreamHttpInputMessage of(ThrowingSupplier<InputStream> body) {
4151
return new InputStreamHttpInputMessage(body);
4252
}
4353

4454
public InputStream getBody() {
45-
return this.body;
55+
return this.body.get();
4656
}
4757

4858
@Override

0 commit comments

Comments
 (0)