-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathAnnotatingElementDeSerializer.cs
More file actions
201 lines (177 loc) · 8.35 KB
/
AnnotatingElementDeSerializer.cs
File metadata and controls
201 lines (177 loc) · 8.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// -------------------------------------------------------------------------------------------------
// <copyright file="AnnotatingElementDeSerializer.cs" company="Starion Group S.A.">
//
// Copyright 2022-2025 Starion Group S.A.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// </copyright>
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!--------
// ------------------------------------------------------------------------------------------------
namespace SysML2.NET.Serializer.Json.Core.DTO
{
using System;
using System.Text.Json;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using SysML2.NET.Common;
using SysML2.NET.Core.DTO.Root.Annotations;
using SysML2.NET.Serializer.Json;
/// <summary>
/// The purpose of the <see cref="AnnotatingElementDeSerializer"/> is to provide deserialization capabilities
/// for the <see cref="IAnnotatingElement"/> interface
/// </summary>
internal static class AnnotatingElementDeSerializer
{
/// <summary>
/// Deserializes an instance of <see cref="IAnnotatingElement"/> from the provided <see cref="JsonElement"/>
/// </summary>
/// <param name="jsonElement">
/// The <see cref="JsonElement"/> that contains the <see cref="IAnnotatingElement"/> json object
/// </param>
/// <param name="serializationModeKind">
/// enumeration specifying what kind of serialization shall be used
/// </param>
/// <param name="loggerFactory">
/// The <see cref="ILoggerFactory"/> used to setup logging
/// </param>
/// <returns>
/// an instance of <see cref="IAnnotatingElement"/>
/// </returns>
internal static IAnnotatingElement DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null)
{
var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("AnnotatingElementDeSerializer");
if (!jsonElement.TryGetProperty("@type"u8, out var @type))
{
throw new InvalidOperationException("The @type property is not available, the AnnotatingElementDeSerializer cannot be used to deserialize this JsonElement");
}
if (@type.GetString() != "AnnotatingElement")
{
throw new InvalidOperationException($"The AnnotatingElementDeSerializer can only be used to deserialize objects of type IAnnotatingElement, a {@type.GetString()} was provided");
}
var dtoInstance = new SysML2.NET.Core.DTO.Root.Annotations.AnnotatingElement();
if (jsonElement.TryGetProperty("@id"u8, out var idProperty))
{
var propertyValue = idProperty.GetString();
if (propertyValue == null)
{
throw new JsonException("The @id property is not present, the AnnotatingElement cannot be deserialized");
}
else
{
dtoInstance.Id = Guid.Parse(propertyValue);
}
}
if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty))
{
foreach (var arrayItem in aliasIdsProperty.EnumerateArray())
{
var propertyValue = arrayItem.GetString();
if (propertyValue != null)
{
dtoInstance.AliasIds.Add(propertyValue);
}
}
}
else
{
logger.LogDebug("the aliasIds Json property was not found in the AnnotatingElement: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("declaredName"u8, out var declaredNameProperty))
{
dtoInstance.DeclaredName = declaredNameProperty.GetString();
}
else
{
logger.LogDebug("the declaredName Json property was not found in the AnnotatingElement: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("declaredShortName"u8, out var declaredShortNameProperty))
{
dtoInstance.DeclaredShortName = declaredShortNameProperty.GetString();
}
else
{
logger.LogDebug("the declaredShortName Json property was not found in the AnnotatingElement: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("elementId"u8, out var elementIdProperty))
{
var propertyValue = elementIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.ElementId = propertyValue;
}
}
else
{
logger.LogDebug("the elementId Json property was not found in the AnnotatingElement: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("isImpliedIncluded"u8, out var isImpliedIncludedProperty))
{
if (isImpliedIncludedProperty.ValueKind != JsonValueKind.Null)
{
dtoInstance.IsImpliedIncluded = isImpliedIncludedProperty.GetBoolean();
}
}
else
{
logger.LogDebug("the isImpliedIncluded Json property was not found in the AnnotatingElement: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty))
{
foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray())
{
if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipIdProperty))
{
var propertyValue = ownedRelationshipIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue));
}
}
}
}
else
{
logger.LogDebug("the ownedRelationship Json property was not found in the AnnotatingElement: { Id }", dtoInstance.Id);
}
if (jsonElement.TryGetProperty("owningRelationship"u8, out var owningRelationshipProperty))
{
if (owningRelationshipProperty.ValueKind == JsonValueKind.Null)
{
dtoInstance.OwningRelationship = null;
}
else
{
if (owningRelationshipProperty.TryGetProperty("@id"u8, out var owningRelationshipIdProperty))
{
var propertyValue = owningRelationshipIdProperty.GetString();
if (propertyValue != null)
{
dtoInstance.OwningRelationship = Guid.Parse(propertyValue);
}
}
}
}
else
{
logger.LogDebug("the owningRelationship Json property was not found in the AnnotatingElement: { Id }", dtoInstance.Id);
}
return dtoInstance;
}
}
}
// ------------------------------------------------------------------------------------------------
// --------THIS IS AN AUTOMATICALLY GENERATED FILE. ANY MANUAL CHANGES WILL BE OVERWRITTEN!--------
// ------------------------------------------------------------------------------------------------