Skip to content

Instantly share code, notes, and snippets.

@suhininalex
Created February 13, 2018 20:25
Show Gist options
  • Save suhininalex/6715ca4c541559de6c50dca1f1ce865a to your computer and use it in GitHub Desktop.
Save suhininalex/6715ca4c541559de6c50dca1f1ce865a to your computer and use it in GitHub Desktop.
data class MethodDescription(
val qualifiedName: String,
val className: String,
val packageName: String,
val declaration: String,
val javaDoc: String,
val content: List<Token>
)
private object TokenSerializer: JsonSerializer<Token>, JsonDeserializer<Token> {
override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): Token = with(context) {
val type = json.asJsonObject["type"].asString
return when (type) {
"LiteralToken" -> deserialize(json, LiteralToken::class.java)
"TypeToken" -> deserialize(json, TypeToken::class.java)
"IdentifierToken" -> deserialize(json, IdentifierToken::class.java)
"CallToken" -> deserialize(json, CallToken::class.java)
else -> throw IllegalArgumentException("There is no registered token class for type $type")
}
}
override fun serialize(src: Token, typeOfSrc: Type, context: JsonSerializationContext): JsonElement {
return context.serialize(src).asJsonObject.apply {
addProperty("type", src.javaClass.simpleName)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment