templates.kotlin-micronaut.common.model.enum.mustache Maven / Gradle / Ivy
/**
* {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}}
*
* @param value The value represented by this enum
{{#isDeprecated}}
*
* @deprecated {{#vendorExtensions.x-deprecated-message}} {{{.}}}{{/vendorExtensions.x-deprecated-message}}
{{/isDeprecated}}
*/
{{#isDeprecated}}
@Deprecated("{{#vendorExtensions.x-deprecated-message}}{{{.}}}{{/vendorExtensions.x-deprecated-message}}")
{{/isDeprecated}}
{{#withXml}}
@XmlType(name="{{datatypeWithEnum}}")
@XmlEnum({{dataType}}.class)
{{/withXml}}
{{#micronaut_serde_jackson}}
@Serdeable
{{/micronaut_serde_jackson}}
{{#generatedAnnotation}}
{{>common/generatedAnnotation}}
{{/generatedAnnotation}}
{{#additionalEnumTypeAnnotations}}
{{{.}}}
{{/additionalEnumTypeAnnotations}}
{{#nonPublicApi}}internal {{/nonPublicApi}}{{#formatSingleLine}}enum class {{>common/model/enumName}}{{/formatSingleLine}}(
@get:JsonValue val value: {{{dataType}}},
) {
{{#allowableValues}}
{{#enumVars}}
{{#enumDescription}}
/**
* {{enumDescription}}
*/
{{/enumDescription}}
{{#withXml}}
@XmlEnumValue({{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}}{{{value}}}{{#isInteger}}"{{/isInteger}}{{#isDouble}}"{{/isDouble}}{{#isLong}}"{{/isLong}}{{#isFloat}}"{{/isFloat}})
{{/withXml}}
{{#deprecated}}
@Deprecated("")
{{/deprecated}}
@JsonProperty({{{strValue}}})
{{{name}}}({{{value}}}),{{#-last}}
;{{/-last}}
{{/enumVars}}
{{/allowableValues}}
override fun toString(): String = {{#isString}}value{{/isString}}{{^isString}}"$value"{{/isString}}
companion object {
@JvmField
val VALUE_MAPPING = entries.associateBy { it.value{{#useEnumCaseInsensitive}}.lowercase(){{/useEnumCaseInsensitive}} }
/**
* Create this enum from a value.
*
* @param value The value
*
* @return The enum
*/
@JsonCreator
@JvmStatic
fun fromValue(value: {{{dataType}}}): {{>common/model/enumName}}{{#isNullable}}?{{/isNullable}} {{openbrace}}{{#formatNoEmptyLines}}
{{#isString}}{{#useEnumCaseInsensitive}}
val key = value.lowercase()
{{/useEnumCaseInsensitive}}{{/isString}}
{{^isNullable}}
{{#isString}}
{{#useEnumCaseInsensitive}}
require(VALUE_MAPPING.containsKey(key)) { "Unexpected value '$key'" }
{{/useEnumCaseInsensitive}}
{{^useEnumCaseInsensitive}}
require(VALUE_MAPPING.containsKey(value)) { "Unexpected value '$value'" }
{{/useEnumCaseInsensitive}}
{{/isString}}
{{^isString}}
require(VALUE_MAPPING.containsKey(value)) { "Unexpected value '$value'" }
{{/isString}}
{{/isNullable}}
return VALUE_MAPPING[{{#isString}}{{#useEnumCaseInsensitive}}key{{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}value{{/useEnumCaseInsensitive}}{{/isString}}{{^isString}}value{{/isString}}]{{^isNullable}}!!{{/isNullable}}
}
{{/formatNoEmptyLines}}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy