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);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.replaymod.render;
|
||||
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.replaymod.core.utils.FileTypeAdapter;
|
||||
import com.replaymod.core.versions.MCVer;
|
||||
import de.johni0702.minecraft.gui.utils.lwjgl.ReadableColor;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
@@ -146,6 +148,7 @@ public class RenderSettings {
|
||||
private final int videoHeight;
|
||||
private final int framesPerSecond;
|
||||
private final int bitRate;
|
||||
@JsonAdapter(FileTypeAdapter.class)
|
||||
private final File outputFile;
|
||||
|
||||
private final boolean renderNameTags;
|
||||
|
||||
Reference in New Issue
Block a user