Skip to content

Commit 2733511

Browse files
committed
Charset argument in RestClientResponseException
See gh-23764
1 parent 4932196 commit 2733511

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

spring-web/src/main/java/org/springframework/web/client/RestClientResponseException.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,22 @@ public byte[] getResponseBodyAsByteArray() {
9999
}
100100

101101
/**
102-
* Return the response body as a string.
102+
* Return the response body converted to String. The charset used is that
103+
* of the response "Content-Type" or otherwise {@code "UTF-8"}.
103104
*/
104105
public String getResponseBodyAsString() {
106+
return getResponseBodyAsString(DEFAULT_CHARSET);
107+
}
108+
109+
/**
110+
* Return the response body converted to String. The charset used is that
111+
* of the response "Content-Type" or otherwise the one given.
112+
* @param fallbackCharset the charset to use on if the response doesn't specify.
113+
* @since 5.1.11
114+
*/
115+
public String getResponseBodyAsString(Charset fallbackCharset) {
105116
if (this.responseCharset == null) {
106-
return new String(this.responseBody, DEFAULT_CHARSET);
117+
return new String(this.responseBody, fallbackCharset);
107118
}
108119
try {
109120
return new String(this.responseBody, this.responseCharset);

0 commit comments

Comments
 (0)