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:
30
src/main/java/com/replaymod/core/utils/FileTypeAdapter.java
Normal file
30
src/main/java/com/replaymod/core/utils/FileTypeAdapter.java
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user