ftl.rest.$$RestModelFromJsonConverterTemplateftl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rxmicro-annotation-processor-rest Show documentation
Show all versions of rxmicro-annotation-processor-rest Show documentation
The RxMicro Annotation Processor internal module that generates common REST components.
The newest version!
<#include "../common-lib.javaftl">
<#-- -------------------------------------------------------------------------------------------------------- -->
public final class ${JAVA_MODEL_CLASS.modelFromJsonConverterImplSimpleClassName} extends ModelFromJsonConverter<${JAVA_MODEL_CLASS.javaSimpleClassName}> {
<#if HAS_PARENT>
private final ${PARENT} parentConverter =
new ${PARENT}();
#if>
<#list JAVA_MODEL_CONVERTER_CHILDREN as CHILD>
private final ${CHILD.modelFromJsonConverterImplSimpleClassName} ${CHILD.fromJsonConverterInstanceName} =
new ${CHILD.modelFromJsonConverterImplSimpleClassName}();
#list>
<#-- ---------------------------------------------------------------------------------------------------------------------------------------------------------- -->
<#if JAVA_MODEL_CLASS.modelClassReturnedByRestMethod>
@Override
public ${JAVA_MODEL_CLASS.javaSimpleClassName} fromJsonObject(final Map params) {
final ${JAVA_MODEL_CLASS.javaSimpleClassName} model = new ${JAVA_MODEL_CLASS.javaSimpleClassName}();
<#if JAVA_MODEL_CLASS.paramEntriesPresentAtThisOrAnyParent>
readParamsToModel(params, model);
<#elseif HAS_PARENT>
parentConverter.readParamsToModel(params, model);
#if>
return model;
}
#if>
<#if JAVA_MODEL_CLASS.paramEntriesPresentAtThisOrAnyParent>
public void readParamsToModel(final Map params,
final ${JAVA_MODEL_CLASS.javaSimpleClassName} model) {
<#if HAS_PARENT>
parentConverter.readParamsToModel(params, model);
#if>
<#list JAVA_MODEL_CLASS.paramEntries as fieldEntry>
<@setParamFieldValue entry=fieldEntry/>
#list>
}
#if>
}
<#-- -------------------------------------------------------------------------------------------------------- -->
<#macro setParamFieldValue entry>
<#assign param = entry.key >
<#if entry.value.object>
<#assign element = entry.value>
<#if param.modelWriteAccessorType.name() == "REFLECTION">
setFieldValue(model, "${param.fieldName}", convertToObjectIfNotNull(${element.fromJsonConverterInstanceName}, params.get("${param.modelName}"), "${param.modelName}"));
<#elseif param.modelWriteAccessorType.name() == "DIRECT">
model.${param.fieldName} = convertToObjectIfNotNull(${element.fromJsonConverterInstanceName}, params.get("${param.modelName}"), "${param.modelName}");
<#elseif param.modelWriteAccessorType.name() == "JAVA_BEAN">
model.${param.setter}(convertToObjectIfNotNull(${element.fromJsonConverterInstanceName}, params.get("${param.modelName}"), "${param.modelName}"));
#if>
<#elseif entry.value.iterable>
<#assign element = entry.value.elementModelClass>
<#assign containerType = entry.value.containerType>
<#if entry.value.primitiveIterable>
<#assign M = element.primitiveType.convertMethod >
<#if param.modelWriteAccessorType.name() == "REFLECTION">
setFieldValue(model, "${param.fieldName}", ${M}${containerType}(params.get("${param.modelName}"), "${param.modelName}"));
<#elseif param.modelWriteAccessorType.name() == "DIRECT">
model.${param.fieldName} = ${M}${containerType}(params.get("${param.modelName}"), "${param.modelName}");
<#elseif param.modelWriteAccessorType.name() == "JAVA_BEAN">
model.${param.setter}(${M}${containerType}(params.get("${param.modelName}"), "${param.modelName}"));
#if>
<#elseif entry.value.enumIterable>
<#if param.modelWriteAccessorType.name() == "REFLECTION">
setFieldValue(model, "${param.fieldName}", toEnum${containerType}(${element.javaSimpleClassName}.class, params.get("${param.modelName}"), "${param.modelName}"));
<#elseif param.modelWriteAccessorType.name() == "DIRECT">
model.${param.fieldName} = toEnum${containerType}(${element.javaSimpleClassName}.class, params.get("${param.modelName}"), "${param.modelName}");
<#elseif param.modelWriteAccessorType.name() == "JAVA_BEAN">
model.${param.setter}(toEnum${containerType}(${element.javaSimpleClassName}.class, params.get("${param.modelName}"), "${param.modelName}"));
#if>
<#elseif entry.value.objectIterable>
<#assign containerType = entry.value.containerType>
<#if param.modelWriteAccessorType.name() == "REFLECTION">
setFieldValue(model, "${param.fieldName}", convertTo${containerType}IfNotNull(${element.fromJsonConverterInstanceName}, params.get("${param.modelName}"), "${param.modelName}"));
<#elseif param.modelWriteAccessorType.name() == "DIRECT">
model.${param.fieldName} = convertTo${containerType}IfNotNull(${element.fromJsonConverterInstanceName}, params.get("${param.modelName}"), "${param.modelName}");
<#elseif param.modelWriteAccessorType.name() == "JAVA_BEAN">
model.${param.setter}(convertTo${containerType}IfNotNull(${element.fromJsonConverterInstanceName}, params.get("${param.modelName}"), "${param.modelName}"));
#if>
#if>
<#elseif entry.value.primitive>
<#assign M = entry.value.primitiveType.convertMethod >
<#if param.modelWriteAccessorType.name() == "REFLECTION">
setFieldValue(model, "${param.fieldName}", ${M}(params.get("${param.modelName}"), "${param.modelName}"));
<#elseif param.modelWriteAccessorType.name() == "DIRECT">
model.${param.fieldName} = ${M}(params.get("${param.modelName}"), "${param.modelName}");
<#elseif param.modelWriteAccessorType.name() == "JAVA_BEAN">
model.${param.setter}(${M}(params.get("${param.modelName}"), "${param.modelName}"));
#if>
<#elseif entry.value.enum>
<#if param.modelWriteAccessorType.name() == "REFLECTION">
setFieldValue(model, "${param.fieldName}", toEnum(${entry.value.javaSimpleClassName}.class, params.get("${param.modelName}"), "${param.modelName}"));
<#elseif param.modelWriteAccessorType.name() == "DIRECT">
model.${param.fieldName} = toEnum(${entry.value.javaSimpleClassName}.class, params.get("${param.modelName}"), "${param.modelName}");
<#elseif param.modelWriteAccessorType.name() == "JAVA_BEAN">
model.${param.setter}(toEnum(${entry.value.javaSimpleClassName}.class, params.get("${param.modelName}"), "${param.modelName}"));
#if>
#if>
#macro>
<#-- -------------------------------------------------------------------------------------------------------- -->