Skip to content

Commit

Permalink
Adopt to changes in Spring Framework 7.
Browse files Browse the repository at this point in the history
See #2449
  • Loading branch information
mp911de committed Jan 16, 2025
1 parent 5cdc3cb commit e7093ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.springframework.data.rest.webmvc.json;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
Expand Down Expand Up @@ -211,7 +212,8 @@ <T> T merge(ObjectNode source, T target, ObjectMapper mapper) {
try {
return doMerge(source, target, mapper);
} catch (Exception o_O) {
throw new HttpMessageNotReadableException("Could not read payload", o_O);
throw new HttpMessageNotReadableException("Could not read payload", o_O,
InputStreamHttpInputMessage.of(() -> new ByteArrayInputStream(mapper.writeValueAsBytes(source))));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,43 @@
package org.springframework.data.rest.webmvc.util;

import java.io.InputStream;
import java.util.function.Supplier;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpInputMessage;
import org.springframework.util.Assert;
import org.springframework.util.function.ThrowingSupplier;

/**
* {@link HttpInputMessage} based on a plain {@link InputStream}, i.e. exposing no headers.
*
* @author Oliver Drotbohm
* @author Mark Paluch
*/
public class InputStreamHttpInputMessage implements HttpInputMessage {

private final InputStream body;
private final Supplier<InputStream> body;

private InputStreamHttpInputMessage(final InputStream body) {
private InputStreamHttpInputMessage(Supplier<InputStream> body) {

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

this.body = body;
}

public static InputStreamHttpInputMessage of(final InputStream body) {
public static InputStreamHttpInputMessage of(InputStream body) {
return new InputStreamHttpInputMessage(() -> body);
}

/**
* @since 5.0
*/
public static InputStreamHttpInputMessage of(ThrowingSupplier<InputStream> body) {
return new InputStreamHttpInputMessage(body);
}

public InputStream getBody() {
return this.body;
return this.body.get();
}

@Override
Expand Down

0 comments on commit e7093ca

Please sign in to comment.