@@ -102,16 +102,28 @@ namespace SysML2.NET.Serializer.Json
102102 }
103103 }
104104 {{ else }}
105- if ({{ structuralFeature.Name }} Property.TryGetProperty("@id", out JsonElement {{ structuralFeature.Name }} IdProperty) )
105+ if ({{ structuralFeature.Name }} Property.ValueKind == JsonValueKind.Null )
106106 {
107- var propertyValue = {{ structuralFeature.Name }} IdProperty.GetString();
108- if (propertyValue != null)
107+ {{ #if (StructuralFeature.QueryIsNullable structuralFeature ) }}
108+ dtoInstance.{{ String.CapitalizeFirstLetter structuralFeature.Name }} = null;
109+ {{ else }}
110+ dtoInstance.{{ String.CapitalizeFirstLetter structuralFeature.Name }} = Guid.Empty;
111+ logger.LogDebug($"the {{ EClass.Name }} .{{ String.CapitalizeFirstLetter structuralFeature.Name }} property was not found in the Json. The value is set to Guid.Empty");
112+ {{ /if }}
113+ }
114+ else
115+ {
116+ if ({{ structuralFeature.Name }} Property.TryGetProperty("@id", out JsonElement {{ structuralFeature.Name }} IdProperty))
109117 {
110- dtoInstance.{{ String.CapitalizeFirstLetter structuralFeature.Name }} = Guid.Parse(propertyValue);
118+ var propertyValue = {{ structuralFeature.Name }} IdProperty.GetString();
119+ if (propertyValue != null)
120+ {
121+ dtoInstance.{{ String.CapitalizeFirstLetter structuralFeature.Name }} = Guid.Parse(propertyValue);
122+ }
111123 }
112124 }
113125 {{ /if }}
114- {{ else if (StructuralFeature.QueryIsAttribute structuralFeature)}}
126+ {{ else if (StructuralFeature.QueryIsAttribute structuralFeature ) }}
115127 {{ #if (StructuralFeature.QueryIsEnumerable structuralFeature )}}
116128 foreach (var arrayItem in {{ structuralFeature.Name }} Property.EnumerateArray())
117129 {
@@ -127,10 +139,10 @@ namespace SysML2.NET.Serializer.Json
127139 {{ else if (StructuralFeature.QueryIsDouble structuralFeature) }}
128140 dtoInstance.{{ String.CapitalizeFirstLetter structuralFeature.Name }} .Add(arrayItem.GetDouble());
129141 {{ else }}
130- throw new NotImplementedException("{{ EClass.Name }} .{{ structuralFeature.Name }} is not yet supported");
142+ throw new NotImplementedException("Enumerable Double - {{ EClass.Name }} .{{ structuralFeature.Name }} is not yet supported");
131143 {{ /if }}
132144 {{ else if (StructuralFeature.QueryIsEnum structuralFeature )}}
133- throw new NotImplementedException("{{ EClass.Name }} .{{ structuralFeature.Name }} is not yet supported");
145+ throw new NotImplementedException("Enumerable Enum - {{ EClass.Name }} .{{ structuralFeature.Name }} is not yet supported");
134146 {{ else }}
135147 var propertyValue = arrayItem.GetString();
136148 if (propertyValue != null)
@@ -139,19 +151,35 @@ namespace SysML2.NET.Serializer.Json
139151 }
140152 {{ /if }}
141153 }
142- {{ else if (StructuralFeature.QueryIsScalar structuralFeature )}}
154+ {{ else if (StructuralFeature.QueryIsNullable structuralFeature ) }}
155+ {{ #if (StructuralFeature.QueryIsBool structuralFeature )}}
156+ dtoInstance.{{ String.CapitalizeFirstLetter structuralFeature.Name }} = {{ structuralFeature.Name }} Property.GetBoolean();
157+ {{ else if (StructuralFeature.QueryIsNumeric structuralFeature )}}
158+ {{ #if (StructuralFeature.QueryIsInteger structuralFeature ) }}
159+ dtoInstance.{{ String.CapitalizeFirstLetter structuralFeature.Name }} = {{ structuralFeature.Name }} Property.GetInt32();
160+ {{ else if (StructuralFeature.QueryIsDouble structuralFeature) }}
161+ dtoInstance.{{ String.CapitalizeFirstLetter structuralFeature.Name }} = {{ structuralFeature.Name }} Property.GetDouble();
162+ {{ else }}
163+ new NotImplementedException("nullable - {{ EClass.Name }} .{{ structuralFeature.Name }} is not yet supported");
164+ {{ /if }}
165+ {{ else if (StructuralFeature.QueryIsEnum structuralFeature )}}
166+ dtoInstance.{{ String.CapitalizeFirstLetter structuralFeature.Name }} = ({{ DTO.TypeName structuralFeature }} )Enum.Parse(typeof({{ DTO.TypeName structuralFeature }} ), {{ structuralFeature.Name }} Property.GetString());
167+ {{ else }}
168+ dtoInstance.{{ String.CapitalizeFirstLetter structuralFeature.Name }} = {{ structuralFeature.Name }} Property.GetString();
169+ {{ /if }}
170+ {{ else if (StructuralFeature.QueryIsScalar structuralFeature ) }}
143171 {{ #if (StructuralFeature.QueryIsBool structuralFeature )}}
144- dtoInstance.{{ String.CapitalizeFirstLetter structuralFeature.Name }} = {{ structuralFeature.Name }} Property.GetBoolean();
172+ dtoInstance.{{ String.CapitalizeFirstLetter structuralFeature.Name }} = {{ structuralFeature.Name }} Property.GetBoolean();
145173 {{ else if (StructuralFeature.QueryIsNumeric structuralFeature )}}
146174 {{ #if (StructuralFeature.QueryIsInteger structuralFeature ) }}
147- dtoInstance.{{ String.CapitalizeFirstLetter structuralFeature.Name }} = {{ structuralFeature.Name }} Property.GetInt32();
175+ dtoInstance.{{ String.CapitalizeFirstLetter structuralFeature.Name }} = {{ structuralFeature.Name }} Property.GetInt32();
148176 {{ else if (StructuralFeature.QueryIsDouble structuralFeature) }}
149- dtoInstance.{{ String.CapitalizeFirstLetter structuralFeature.Name }} = {{ structuralFeature.Name }} Property.GetDouble();
177+ dtoInstance.{{ String.CapitalizeFirstLetter structuralFeature.Name }} = {{ structuralFeature.Name }} Property.GetDouble();
150178 {{ else }}
151- throw new NotImplementedException("{{ EClass.Name }} .{{ structuralFeature.Name }} is not yet supported");
179+ new NotImplementedException("Scalar - {{ EClass.Name }} .{{ structuralFeature.Name }} is not yet supported");
152180 {{ /if }}
153181 {{ else if (StructuralFeature.QueryIsEnum structuralFeature )}}
154- throw new NotImplementedException(" {{ EClass.Name }} . {{ structuralFeature.Name }} is not yet supported" );
182+ dtoInstance. {{ String.CapitalizeFirstLetter structuralFeature.Name }} = ( {{ DTO.TypeName structuralFeature }} )Enum.Parse(typeof( {{ DTO.TypeName structuralFeature }} ), {{ structuralFeature.Name }} Property.GetString() );
155183 {{ else }}
156184 var propertyValue = {{ structuralFeature.Name }} Property.GetString();
157185 if (propertyValue != null)
@@ -160,7 +188,7 @@ namespace SysML2.NET.Serializer.Json
160188 }
161189 {{ /if }}
162190 {{ else }}
163- throw new NotImplementedException("{{ EClass.Name }} .{{ structuralFeature.Name }} is not yet supported");
191+ throw new NotImplementedException("{{ EClass.Name }} .{{ structuralFeature.Name }} is not supported");
164192 {{ /if }}
165193 {{ /if }}
166194 }
0 commit comments