jafea7-ctbrec-v5.3.2-based/common/src/main/java/ctbrec/io/FileJsonAdapter.java

31 lines
725 B
Java

package ctbrec.io;
import java.io.File;
import java.io.IOException;
import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.JsonReader;
import com.squareup.moshi.JsonWriter;
public class FileJsonAdapter extends JsonAdapter<File> {
@Override
public File fromJson(JsonReader reader) throws IOException {
String path = reader.nextString();
if (path != null) {
return new File(path);
} else {
return null;
}
}
@Override
public void toJson(JsonWriter writer, File value) throws IOException {
if (value != null) {
writer.value(value.getCanonicalPath());
} else {
writer.nullValue();
}
}
}