de.lancom.openapi.entity.JsonEntityFactory.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openapi-parser Show documentation
Show all versions of openapi-parser Show documentation
This open-source project provides an OpenAPI 3.0 Parser implemented in Kotlin, utilizing immutable data classes
package de.lancom.openapi.entity
import com.fasterxml.jackson.databind.node.*
import de.lancom.openapi.jackson.Parser
interface JsonEntityFactory : Parser {
operator fun invoke(number: Number): E {
return when (number) {
is Int ->
this(number)
is Long ->
this(number)
is Double ->
this(number)
else ->
throw NotImplementedError()
}
}
operator fun invoke(int: Int): E {
return parseJsonNode(IntNode(int))
}
operator fun invoke(long: Long): E {
return parseJsonNode(LongNode(long))
}
operator fun invoke(double: Double): E {
return parseJsonNode(DoubleNode(double))
}
operator fun invoke(boolean: Boolean): E {
return parseJsonNode(if (boolean) BooleanNode.TRUE else BooleanNode.FALSE)
}
operator fun invoke(string: String): E {
return parseJsonNode(TextNode(string))
}
}