Merge branch 'ConnectAPI' of https://codefirst.iut.uca.fr/git/WhatTheFantasy/WF-Android into ConnectAPI
commit
694ccdab1e
@ -1,6 +1,31 @@
|
||||
package com.example.what_the_fantasy.data.model
|
||||
import com.google.gson.*
|
||||
import java.lang.reflect.Type
|
||||
|
||||
enum class SrcLanguage(val code:Int) {
|
||||
vf(1),
|
||||
vo(0);
|
||||
|
||||
companion object {
|
||||
fun fromCode(code: Int): SrcLanguage? = values().find { it.code == code }
|
||||
}
|
||||
}
|
||||
|
||||
class LangAdapter : JsonSerializer<SrcLanguage>, JsonDeserializer<SrcLanguage> {
|
||||
override fun serialize(
|
||||
src: SrcLanguage?,
|
||||
typeOfSrc: Type?,
|
||||
context: JsonSerializationContext?
|
||||
): JsonElement = JsonPrimitive(src?.code)
|
||||
|
||||
override fun deserialize(
|
||||
json: JsonElement?,
|
||||
typeOfT: Type?,
|
||||
context: JsonDeserializationContext?
|
||||
): SrcLanguage {
|
||||
val code = json?.asInt
|
||||
return SrcLanguage.fromCode(code ?: throw JsonParseException("Code null"))
|
||||
?: throw JsonParseException("Unknown Status code: $code")
|
||||
}
|
||||
|
||||
enum class SrcLanguage {
|
||||
vf,
|
||||
vo
|
||||
}
|
Loading…
Reference in new issue