Skip to content
Permalink
Browse files
JCLOUDS-1559: Add explicit Charset to fromJson calls
  • Loading branch information
gaul committed Dec 5, 2020
1 parent e788535 commit 2e9ae3b3af1c94f7931b15f7d1cfb87bdf141ab8
Showing 2 changed files with 4 additions and 2 deletions.
@@ -27,6 +27,7 @@
import org.jclouds.json.Json;

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.Set;

import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream;
@@ -56,7 +57,7 @@ public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) {
// Content can be null in the case of HEAD requests
if (response.getPayload() != null) {
closeClientButKeepContentStream(response);
ErrorMessage error = json.fromJson(new ByteArrayInputStream(content), ErrorMessage.class);
ErrorMessage error = json.fromJson(new ByteArrayInputStream(content), StandardCharsets.UTF_8, ErrorMessage.class);
if (error != null) {
return shouldRetryRequestOnError(command, response, error);
}
@@ -30,6 +30,7 @@

import javax.annotation.Resource;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import static org.jclouds.http.HttpUtils.releasePayload;

@@ -48,7 +49,7 @@ protected ParseResponse(Json json, String propertyName) {
public String apply(HttpResponse from) {
Response response = null;
try (InputStream gson = from.getPayload().openStream()) {
response = json.fromJson(gson, TypeLiteral.get(Response.class).getType());
response = json.fromJson(gson, StandardCharsets.UTF_8, TypeLiteral.get(Response.class).getType());
return tryFindInfoPropertyValue(response);
} catch (Exception e) {
StringBuilder message = new StringBuilder();

0 comments on commit 2e9ae3b

Please sign in to comment.