Created
January 14, 2019 22:01
-
-
Save mikeseif/0a50a6fcb7c7c355a834471da16e9955 to your computer and use it in GitHub Desktop.
Live Template for CDoc<T, R, L>,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Serializable | |
data class $NAME$(override val version: String, | |
override val href: String, | |
override val attributes: $ATTRTYPE$, | |
override val items: List<$ITEMTYPE$>, | |
override val links: $LINKTYPE$): CDoc<$ATTRTYPE$, $ITEMTYPE$, $LINKTYPE$> { | |
@Serializer(forClass = $NAME$::class) | |
companion object: KSerializer<$NAME$> { | |
@ImplicitReflectionSerializer | |
override fun deserialize(input: Decoder): $NAME$ { | |
val jsonReader = input as? JSON.JsonInput ?: throw SerializationException("This class can be loaded only by JSON") | |
val tree = jsonReader.readAsTree() as? JsonObject ?: throw SerializationException("Expected JSON object") | |
val itemsJo = tree["items"].jsonArray | |
val items = itemsJo.parseToFailableList<$ITEMTYPE$>() | |
val version = tree["version"].toString() | |
val href = tree["href"].toString() | |
val attributes = JSON.nonstrict.parse($ATTRTYPE$::class.serializer(), tree["attributes"].toString()) | |
val links = JSON.nonstrict.parse($LINKTYPE$::class.serializer(), tree["links"].toString()) | |
return $NAME$(version, href, attributes, items, links) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment