Skip to content

Commit 1780e73

Browse files
committed
Add custom gson adapter
1 parent 5bebe82 commit 1780e73

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package net.onelitefeather.plugindebug
2+
3+
import com.google.gson.TypeAdapter
4+
import com.google.gson.stream.JsonReader
5+
import com.google.gson.stream.JsonWriter
6+
import java.nio.file.Paths
7+
import kotlin.io.path.name
8+
9+
internal class DebugFileAdapter : TypeAdapter<DebugFile>() {
10+
override fun write(out: JsonWriter, value: DebugFile) {
11+
out
12+
.beginObject()
13+
.name("filePath").value(value.filePath.name)
14+
.name("fileType").value(value.fileType.name)
15+
.name("uiTabName").value(value.uiTabName)
16+
.endObject()
17+
}
18+
19+
override fun read(`in`: JsonReader): DebugFile {
20+
`in`.beginObject()
21+
val filePath = `in`.nextString()
22+
val fileType = FileType.valueOf(`in`.nextString())
23+
val uiTabName = `in`.nextString()
24+
`in`.endObject()
25+
return DebugFile(Paths.get(filePath), fileType, uiTabName)
26+
}
27+
}

0 commit comments

Comments
 (0)