[HOTFIX] Фикс десереализации старых byte[].

This commit is contained in:
Zaxar163 2019-06-11 10:41:10 +03:00
parent d6b747ddc1
commit 084b84a6a2

View file

@ -13,6 +13,7 @@
import javax.script.ScriptEngineManager; import javax.script.ScriptEngineManager;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer; import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
@ -144,6 +145,14 @@ private static class ByteArrayToBase64TypeAdapter implements JsonSerializer<byte
private Base64.Decoder decoder = Base64.getUrlDecoder(); private Base64.Decoder decoder = Base64.getUrlDecoder();
private Base64.Encoder encoder = Base64.getUrlEncoder(); private Base64.Encoder encoder = Base64.getUrlEncoder();
public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (json.isJsonArray()) {
JsonArray byteArr = json.getAsJsonArray();
byte[] arr = new byte[byteArr.size()];
for (int i = 0; i < arr.length; i++) {
arr[i] = byteArr.get(i).getAsByte();
}
return arr;
}
return decoder.decode(json.getAsString()); return decoder.decode(json.getAsString());
} }