enum convertion added

This commit is contained in:
Elena Bobkova 2018-11-19 16:56:23 +03:00
parent 786b297972
commit 46c0f736ac
4 changed files with 6 additions and 24 deletions

View File

@ -11,7 +11,7 @@ import com.fasterxml.jackson.annotation.JsonValue
*/
enum class {{ name }}(val code: {{ utils.formatEnumValueType(valuesTypes) }}) {
{%- include 'blocks/enum/cases.twig' with { values: values } %}
{%- include 'blocks/enum/cases.twig' with { valuesTypes: valuesTypes, values: values } %}
@JsonValue
fun toValue() = code

View File

@ -6,5 +6,5 @@
* {{ value.description }}
*/
{%- endif %}
{{ value.nameUpperCaseWithUnderscope }}{%- if not (loop.last) %},{% else %};{% endif %}
{{ value.nameUpperCaseWithUnderscope }}({{ utils.formatEnumValue(valuesTypes, value) }}){%- if not (loop.last) %},{% else %};{% endif %}
{%- endfor -%}

View File

@ -1,22 +0,0 @@
{%- if storable %}
@TypeConverter
@Nullable
public static String serialize(@Nullable final {{ name }} value) {
if (value == null) {
return null;
}
return value.name();
}
@TypeConverter
@Nullable
public static {{ name }} deserialize(@Nullable final String value) {
if (value == null) {
return null;
}
return {{ name }}.valueOf(value);
}
{%- endif -%}

View File

@ -33,4 +33,8 @@ List<{{ self.formatValueType(valueType.itemsType, true, true) }}>
{% macro formatEnumValueType(valuesTypes) %}
{%- if valuesTypes == "STRING" -%}String{%- elseif valuesTypes == "INT" -%}Int{%- endif -%}
{% endmacro %}
{% macro formatEnumValue(valuesTypes, value) %}
{%- if valuesTypes == "STRING" -%}"{{ value.value }}"{%- elseif valuesTypes == "INT" -%}{{ value.value }}{%- endif -%}
{% endmacro %}