diff --git a/KotlinServer/Class.kt.twig b/KotlinServer/Class.kt.twig index 54c0703..5529222 100644 --- a/KotlinServer/Class.kt.twig +++ b/KotlinServer/Class.kt.twig @@ -4,9 +4,10 @@ package {{ packageName }}.api import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.annotation.JsonFormat import java.math.BigDecimal -import org.joda.time.DateTime //TODO update +import java.time.ZonedDateTime {%- if (description is not empty) %} diff --git a/KotlinServer/blocks/class/constructor-fields-info.twig b/KotlinServer/blocks/class/constructor-fields-info.twig index 6c14f1f..6789f10 100644 --- a/KotlinServer/blocks/class/constructor-fields-info.twig +++ b/KotlinServer/blocks/class/constructor-fields-info.twig @@ -1,5 +1,13 @@ {%- import '../../utils.twig' as utils -%} {%- for field in fields %} - {{ utils.writeInclusionAnnotation(field.nullable, field.optional) }}{%- if includeVal %}val {% endif %}{{ field.name }}: {{ utils.formatValueType(field.type.type, field.nullable, field.optional) }}{{ utils.writeNullCheckMark(field.nullable, field.optional) }} {%- if (not (loop.last)) or (addCommaAtTheEnd)%}, {% endif %} + {%- if field.type.type.baseTypeName == "DateTime" %} + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssX", timezone = "UTC") //TODO use field format + {%- endif %} + {%- if field.nullable %} + @JsonInclude(JsonInclude.Include.ALWAYS) + {%- elseif field.optional %} + @JsonInclude(JsonInclude.Include.NON_NULL) + {%- endif %} + {% if includeVal %}val {% endif %}{{ field.name }}: {{ utils.formatValueType(field.type.type, field.nullable, field.optional) }}{{ utils.writeNullCheckMark(field.nullable, field.optional) }} {%- if (not (loop.last)) or (addCommaAtTheEnd)%}, {% endif %} {%- endfor -%} \ No newline at end of file diff --git a/KotlinServer/utils.twig b/KotlinServer/utils.twig index 63166b9..e353148 100644 --- a/KotlinServer/utils.twig +++ b/KotlinServer/utils.twig @@ -16,10 +16,18 @@ {%- endif -%} {% endmacro %} +{% macro includeDateFormat(valueType) %} +{%- if valueType.baseTypeName == "DateTime" -%} +@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssX", timezone = "UTC") +{%- endif -%} +{% endmacro %} + {% macro formatValueType(valueType, nullable, optional) %} {% import _self as self %} {%- if valueType.baseTypeName == "Bool" -%} Boolean +{%- elseif valueType.baseTypeName == "DateTime" -%} +ZonedDateTime {%- elseif valueType.baseTypeName == "Decimal" -%} BigDecimal {%- elseif valueType.baseTypeName == "Map" -%}