Skip to content

Commit

Permalink
fix #502 获取String类型数据时,自动去除换行符等转译字符,如获取h5网页内容
Browse files Browse the repository at this point in the history
  • Loading branch information
liujingxing committed Aug 20, 2024
1 parent f946e4b commit b809e04
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ class SerializationConverter(
if (needDecodeResult) {
json = RxHttpPlugins.onResultDecoder(json)
}
if (type == String::class.java) {
return json as T
}
val serializer = format.serializersModule.serializer(type)
return format.decodeFromString(serializer, json) as T
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,17 @@ public static GsonConverter create(Gson gson, MediaType contentType) {
}

@NotNull
@SuppressWarnings("unchecked")
@Override
public <T> T convert(@NotNull ResponseBody body, @NotNull Type type, boolean needDecodeResult) throws IOException {
try {
String result = body.string();
T t;
if (needDecodeResult) {
String result = body.string();
result = RxHttpPlugins.onResultDecoder(result);
t = gson.fromJson(result, type);
} else {
t = gson.fromJson(body.charStream(), type);
}
if (type == String.class) return (T) result;
T t = gson.fromJson(result, type);
if (t == null) {
throw new IllegalStateException("GsonConverter Could not deserialize body as " + type);
}
Expand Down

0 comments on commit b809e04

Please sign in to comment.