All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.lancom.openapi.entity.JsonEntityFactory.kt Maven / Gradle / Ivy

Go to download

This open-source project provides an OpenAPI 3.0 Parser implemented in Kotlin, utilizing immutable data classes

There is a newer version: 2.1.1
Show newest version
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))
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy