Fix RenderSettings (de)serialization with Java 16 (fixes #520)

Turns out we were relying on the implementation detail of the File class, and
Java 16 ensures we cannot do that.
This commit is contained in:
Jonas Herzig
2021-06-05 13:04:23 +02:00
parent 9d3583293b
commit 25a6cdc502
2 changed files with 33 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
package com.replaymod.core.utils;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import java.io.File;
import java.io.IOException;
public class FileTypeAdapter extends TypeAdapter<File> {
@Override
public void write(JsonWriter out, File value) throws IOException {
out.value(value.getPath());
}
@Override
public File read(JsonReader in) throws IOException {
String path;
if (in.peek() == JsonToken.BEGIN_OBJECT) {
in.beginObject();
in.nextName();
path = in.nextString();
in.endObject();
} else {
path = in.nextString();
}
return new File(path);
}
}