fix bugs.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package com.xscm.moduleutil.utils
|
||||
|
||||
import com.google.gson.TypeAdapter
|
||||
import com.google.gson.stream.JsonReader
|
||||
import com.google.gson.stream.JsonToken
|
||||
import com.google.gson.stream.JsonWriter
|
||||
|
||||
class NullToEmptyStringAdapter : TypeAdapter<String>() {
|
||||
override fun write(out: JsonWriter, value: String?) {
|
||||
out.value(value ?: "")
|
||||
}
|
||||
|
||||
override fun read(`in`: JsonReader): String {
|
||||
return if (`in`.peek() == JsonToken.NULL) {
|
||||
`in`.nextNull()
|
||||
"" // null → 空字符串
|
||||
} else {
|
||||
`in`.nextString() ?: ""
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user