Created
February 13, 2018 20:25
-
-
Save suhininalex/6715ca4c541559de6c50dca1f1ce865a to your computer and use it in GitHub Desktop.
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
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