Merge pull request #45 from TouchInstinct/java_optional
Java: nullable for all optional fields
This commit is contained in:
commit
e59f073d51
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
@TypeConverter
|
||||
@Nullable
|
||||
public static String serialize{{ field.type.type.itemsType.baseTypeName }}List(@Nullable final {{ utils.formatValueType(field.type.type, true) }} value) {
|
||||
public static String serialize{{ field.type.type.itemsType.baseTypeName }}List(@Nullable final {{ utils.formatValueType(field.type.type, true, true) }} value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -24,12 +24,12 @@
|
|||
|
||||
@TypeConverter
|
||||
@Nullable
|
||||
public static {{ utils.formatValueType(field.type.type, true) }} deserialize{{ field.type.type.itemsType.baseTypeName }}List(@Nullable final String value) {
|
||||
public static {{ utils.formatValueType(field.type.type, true, true) }} deserialize{{ field.type.type.itemsType.baseTypeName }}List(@Nullable final String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return LoganSquare.parseList(value, {{ utils.formatValueType(field.type.type.itemsType, true) }}.class);
|
||||
return LoganSquare.parseList(value, {{ utils.formatValueType(field.type.type.itemsType, true, true) }}.class);
|
||||
} catch (final IOException exception) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
|
||||
@TypeConverter
|
||||
@Nullable
|
||||
public static String serialize{{ field.type.type.valuesType.baseTypeName }}Map(@Nullable final {{ utils.formatValueType(field.type.type, true) }} value) {
|
||||
public static String serialize{{ field.type.type.valuesType.baseTypeName }}Map(@Nullable final {{ utils.formatValueType(field.type.type, true, true) }} value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -53,12 +53,12 @@
|
|||
|
||||
@TypeConverter
|
||||
@Nullable
|
||||
public static {{ utils.formatValueType(field.type.type, true) }} deserialize{{ field.type.type.valuesType.baseTypeName }}Map(@Nullable final String value) {
|
||||
public static {{ utils.formatValueType(field.type.type, true, true) }} deserialize{{ field.type.type.valuesType.baseTypeName }}Map(@Nullable final String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return LoganSquare.parseMap(value, {{ utils.formatValueType(field.type.type.valuesType, true) }}.class);
|
||||
return LoganSquare.parseMap(value, {{ utils.formatValueType(field.type.type.valuesType, true, true) }}.class);
|
||||
} catch (final IOException exception) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -74,7 +74,7 @@
|
|||
|
||||
@TypeConverter
|
||||
@Nullable
|
||||
public static String serialize{{ field.type.type.baseTypeName }}(@Nullable final {{ utils.formatValueType(field.type.type, true) }} value) {
|
||||
public static String serialize{{ field.type.type.baseTypeName }}(@Nullable final {{ utils.formatValueType(field.type.type, true, true) }} value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -87,12 +87,12 @@
|
|||
|
||||
@TypeConverter
|
||||
@Nullable
|
||||
public static {{ utils.formatValueType(field.type.type, true) }} deserialize{{ field.type.type.baseTypeName }}(@Nullable final String value) {
|
||||
public static {{ utils.formatValueType(field.type.type, true, true) }} deserialize{{ field.type.type.baseTypeName }}(@Nullable final String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return LoganSquare.parse(value, {{ utils.formatValueType(field.type.type, true) }}.class);
|
||||
return LoganSquare.parse(value, {{ utils.formatValueType(field.type.type, true, true) }}.class);
|
||||
} catch (final IOException exception) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@
|
|||
* {{ field.description }}
|
||||
*/
|
||||
{%- endif %}
|
||||
{{ utils.writeNullCheckAnnotation(field.type.type.baseTypeName, field.nullable) }}
|
||||
public {{ utils.formatValueType(field.type.type, field.nullable) }} {% if (field.type.type.baseTypeName == "Bool") and (field.name matches "^is[A-Z,0-9].*") -%}{{ field.name }}{%- else -%}get{{ capitalize(field.name) }}{%- endif -%}() {
|
||||
{%- if field.nullable %}
|
||||
{{ utils.writeNullCheckAnnotation(field.type.type.baseTypeName, field.nullable, field.optional) }}
|
||||
public {{ utils.formatValueType(field.type.type, field.nullable, field.optional) }} {% if (field.type.type.baseTypeName == "Bool") and (field.name matches "^is[A-Z,0-9].*") -%}{{ field.name }}{%- else -%}get{{ capitalize(field.name) }}{%- endif -%}() {
|
||||
{%- if field.nullable or field.optional %}
|
||||
if (this.{{ field.name }} == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@
|
|||
* {{ field.description }}
|
||||
*/
|
||||
{%- endif %}
|
||||
public void set{{ capitalize(field.name) }}({{ utils.writeNullCheckAnnotation(field.type.type.baseTypeName, field.nullable) }} final {{ utils.formatValueType(field.type.type, field.nullable) }} {{ field.name }}) {
|
||||
public void set{{ capitalize(field.name) }}({{ utils.writeNullCheckAnnotation(field.type.type.baseTypeName, field.nullable, field.optional) }} final {{ utils.formatValueType(field.type.type, field.nullable, field.optional) }} {{ field.name }}) {
|
||||
this.{{ field.name }} = {{ field.name }};
|
||||
}
|
||||
{%- endfor -%}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{%- import '../../utils.twig' as utils -%}
|
||||
{% for field in fields %}
|
||||
{%- if field.nullable %}
|
||||
this.{{ field.name }} = ({{ utils.formatValueType(field.type.type, field.nullable) }}) inputStream.readObject();
|
||||
{%- if field.nullable or field.optional %}
|
||||
this.{{ field.name }} = ({{ utils.formatValueType(field.type.type, field.nullable, field.optional) }}) inputStream.readObject();
|
||||
{%- elseif field.type.type.baseTypeName == "Int" %}
|
||||
this.{{ field.name }} = inputStream.readInt();
|
||||
{%- elseif field.type.type.baseTypeName == "Long" %}
|
||||
|
|
@ -13,6 +13,6 @@
|
|||
{%- elseif field.type.type.baseTypeName == "Bool" %}
|
||||
this.{{ field.name }} = inputStream.readBoolean();
|
||||
{%- else %}
|
||||
this.{{ field.name }} = ({{ utils.formatValueType(field.type.type, field.nullable) }}) inputStream.readObject();
|
||||
this.{{ field.name }} = ({{ utils.formatValueType(field.type.type, field.nullable, field.optional) }}) inputStream.readObject();
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{%- import '../../utils.twig' as utils -%}
|
||||
{%- for field in fields %}
|
||||
{%- if not (field.nullable)
|
||||
{%- if not (field.nullable or field.optional)
|
||||
and field.type.type.baseTypeName != "Int"
|
||||
and field.type.type.baseTypeName != "Long"
|
||||
and field.type.type.baseTypeName != "Double"
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
validateNotNull(this.{{ field.name }});
|
||||
{%- endif %}
|
||||
{%- if field.type.type.baseTypeName == "Map" %}
|
||||
{%- if field.nullable %}
|
||||
{%- if field.nullable or field.optional %}
|
||||
if (this.{{ field.name }} != null) {
|
||||
validateCollection(this.{{ field.name }}.values(), CollectionValidationRule.EXCEPTION_IF_ANY_INVALID);
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
validateCollection(this.{{ field.name }}.values(), CollectionValidationRule.EXCEPTION_IF_ANY_INVALID);
|
||||
{%- endif %}
|
||||
{%- elseif field.type.type.baseTypeName == "Array" %}
|
||||
{%- if field.nullable %}
|
||||
{%- if field.nullable or field.optional %}
|
||||
if (this.{{ field.name }} != null) {
|
||||
validateCollection(this.{{ field.name }}, CollectionValidationRule.EXCEPTION_IF_ANY_INVALID);
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@
|
|||
and field.type.type.baseTypeName != "DateTime"
|
||||
and (field.type.values is empty) %}
|
||||
if (this.{{ field.name }} instanceof ApiModel) {
|
||||
{%- if field.nullable %}
|
||||
{%- if field.nullable or field.optional %}
|
||||
if (this.{{ field.name }} != null) {
|
||||
((ApiModel) this.{{ field.name }}).validate();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
{% for field in fields %}
|
||||
{%- if field.nullable %}
|
||||
{%- if field.nullable or field.optional %}
|
||||
outputStream.writeObject(this.{{ field.name }});
|
||||
{%- elseif field.type.type.baseTypeName == "Int" %}
|
||||
outputStream.writeInt(this.{{ field.name }});
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
* {{ field.description }}
|
||||
*/
|
||||
{%- endif %}
|
||||
{{ utils.writeNullCheckAnnotation(field.type.type.baseTypeName, field.nullable) }}
|
||||
{{ utils.writeNullCheckAnnotation(field.type.type.baseTypeName, field.nullable, field.optional) }}
|
||||
{%- if (storageAttributes is not null) %}
|
||||
{%- if (field.type.storable) %}
|
||||
@TypeConverters({{ field.type.type.baseTypeName }}.class)
|
||||
|
|
@ -17,5 +17,5 @@
|
|||
{%- endif %}
|
||||
{%- endif %}
|
||||
@JsonField(name = "{{ field.jsonName }}")
|
||||
private {{ utils.formatValueType(field.type.type, field.nullable) }} {{ field.name }};
|
||||
private {{ utils.formatValueType(field.type.type, field.nullable, field.optional) }} {{ field.name }};
|
||||
{%- endfor -%}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
{%- if fields is not empty -%}
|
||||
{%- for field in fields %}
|
||||
{{ utils.writeNullCheckAnnotation(field.type.type.baseTypeName, field.nullable) }} final {{ utils.formatValueType(field.type.type, field.nullable) }} {{ field.name }} {%- if not (loop.last) %}, {% endif %}
|
||||
{{ utils.writeNullCheckAnnotation(field.type.type.baseTypeName, field.nullable, field.optional) }} final {{ utils.formatValueType(field.type.type, field.nullable, field.optional) }} {{ field.name }} {%- if not (loop.last) %}, {% endif %}
|
||||
{%- endfor -%}
|
||||
{%- endif -%}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
{%- if typeParameters is not empty -%}
|
||||
<
|
||||
{%- for typeParameter in typeParameters %}
|
||||
{{- utils.formatValueType(typeParameter, true) -}}{%- if not (loop.last) %}, {% endif %}
|
||||
{{- utils.formatValueType(typeParameter, true, true) -}}{%- if not (loop.last) %}, {% endif %}
|
||||
{%- endfor -%}
|
||||
>
|
||||
{%- endif -%}
|
||||
|
|
|
|||
Loading…
Reference in New Issue