diff --git a/SySML2.NET.REST/RestClient.cs b/SySML2.NET.REST/RestClient.cs index 13aebd13..5448ccb7 100644 --- a/SySML2.NET.REST/RestClient.cs +++ b/SySML2.NET.REST/RestClient.cs @@ -410,7 +410,7 @@ private async Task> RequestData(Uri requestUri, CancellationT using var stream = await response.Content.ReadAsStreamAsync(); - var result = await this.deserializer.DeSerializeAsync(stream, SerializationModeKind.JSON, SerializationTargetKind.PSM, cancellationToken); + var result = await this.deserializer.DeSerializeAsync(stream, SerializationModeKind.JSON, SerializationTargetKind.PSM, false, cancellationToken); return result; } diff --git a/SysML2.NET.API/Modules/ProjectModule.cs b/SysML2.NET.API/Modules/ProjectModule.cs index e8119e3a..914253cd 100644 --- a/SysML2.NET.API/Modules/ProjectModule.cs +++ b/SysML2.NET.API/Modules/ProjectModule.cs @@ -140,7 +140,7 @@ await WriteResultsToResponse(dataItems, SerializationModeKind.JSON, res, jsonWri var stream = new MemoryStream(); await req.Body.CopyToAsync(stream, cancellationToken); - var dataItems = await this.deserializer.DeSerializeAsync(stream, SerializationModeKind.JSON, SerializationTargetKind.PSM, CancellationToken.None); + var dataItems = await this.deserializer.DeSerializeAsync(stream, SerializationModeKind.JSON, SerializationTargetKind.PSM, false, CancellationToken.None); var project = (Project)dataItems.Single(); diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/AnnotatingElementDeSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/AnnotatingElementDeSerializer.cs index 6669c5a9..92a4ff81 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/AnnotatingElementDeSerializer.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/AnnotatingElementDeSerializer.cs @@ -49,13 +49,16 @@ internal static class AnnotatingElementDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IAnnotatingElement DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IAnnotatingElement DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("AnnotatingElementDeSerializer"); @@ -85,6 +88,33 @@ internal static IAnnotatingElement DeSerialize(JsonElement jsonElement, Serializ } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Root.Annotations.AnnotatingElement dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -465,8 +495,128 @@ internal static IAnnotatingElement DeSerialize(JsonElement jsonElement, Serializ logger.LogDebug("the textualRepresentation Json property was not found in the AnnotatingElement: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Root.Annotations.AnnotatingElement dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.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; } } } diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/AssociationDeSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/AssociationDeSerializer.cs index 416adac3..ec742265 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/AssociationDeSerializer.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/AssociationDeSerializer.cs @@ -49,13 +49,16 @@ internal static class AssociationDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IAssociation DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IAssociation DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("AssociationDeSerializer"); @@ -85,6 +88,33 @@ internal static IAssociation DeSerialize(JsonElement jsonElement, SerializationM } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Associations.Association dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1105,8 +1135,208 @@ internal static IAssociation DeSerialize(JsonElement jsonElement, SerializationM logger.LogDebug("the unioningType Json property was not found in the Association: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Associations.Association dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Association: { 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 Association: { 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 Association: { 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 Association: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Association: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Association: { 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 Association: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Association: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Association: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Association: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Association: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Association: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/DependencyDeSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/DependencyDeSerializer.cs index 096b32ba..395bd669 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/DependencyDeSerializer.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/DependencyDeSerializer.cs @@ -49,13 +49,16 @@ internal static class DependencyDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IDependency DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IDependency DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("DependencyDeSerializer"); @@ -85,6 +88,33 @@ internal static IDependency DeSerialize(JsonElement jsonElement, SerializationMo } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Root.Dependencies.Dependency dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -497,8 +527,224 @@ internal static IDependency DeSerialize(JsonElement jsonElement, SerializationMo logger.LogDebug("the textualRepresentation Json property was not found in the Dependency: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Root.Dependencies.Dependency dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Dependency: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("client"u8, out var clientProperty)) + { + foreach (var arrayItem in clientProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var clientExternalIdProperty)) + { + var propertyValue = clientExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Client.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the client Json property was not found in the Dependency: { 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 Dependency: { 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 Dependency: { 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 Dependency: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Dependency: { 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 Dependency: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Dependency: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Dependency: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Dependency: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Dependency: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("supplier"u8, out var supplierProperty)) + { + foreach (var arrayItem in supplierProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var supplierExternalIdProperty)) + { + var propertyValue = supplierExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Supplier.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the supplier Json property was not found in the Dependency: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/EnumerationDefinitionDeSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/EnumerationDefinitionDeSerializer.cs index 97080515..4ca247c1 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/EnumerationDefinitionDeSerializer.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/EnumerationDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class EnumerationDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IEnumerationDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IEnumerationDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("EnumerationDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IEnumerationDefinition DeSerialize(JsonElement jsonElement, Seri } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Enumerations.EnumerationDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1617,8 +1647,164 @@ internal static IEnumerationDefinition DeSerialize(JsonElement jsonElement, Seri logger.LogDebug("the variantMembership Json property was not found in the EnumerationDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Enumerations.EnumerationDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 EnumerationDefinition: { 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 EnumerationDefinition: { 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 EnumerationDefinition: { 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 EnumerationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the EnumerationDefinition: { 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 EnumerationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the EnumerationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the EnumerationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the EnumerationDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the EnumerationDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/FeatureDeSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/FeatureDeSerializer.cs index 36de4a24..3a5ec4d3 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/FeatureDeSerializer.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/FeatureDeSerializer.cs @@ -49,13 +49,16 @@ internal static class FeatureDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IFeature DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IFeature DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("FeatureDeSerializer"); @@ -85,6 +88,33 @@ internal static IFeature DeSerialize(JsonElement jsonElement, SerializationModeK } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.Feature dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1419,8 +1449,257 @@ internal static IFeature DeSerialize(JsonElement jsonElement, SerializationModeK logger.LogDebug("the unioningType Json property was not found in the Feature: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.Feature dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Feature: { 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 Feature: { 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 Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the Feature: { 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 Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the Feature: { 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 Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Feature: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Feature: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/FeatureTypingDeSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/FeatureTypingDeSerializer.cs index 5e26ee9e..e0358dfe 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/FeatureTypingDeSerializer.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/FeatureTypingDeSerializer.cs @@ -49,13 +49,16 @@ internal static class FeatureTypingDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IFeatureTyping DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IFeatureTyping DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("FeatureTypingDeSerializer"); @@ -85,6 +88,33 @@ internal static IFeatureTyping DeSerialize(JsonElement jsonElement, Serializatio } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.FeatureTyping dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -531,8 +561,234 @@ internal static IFeatureTyping DeSerialize(JsonElement jsonElement, Serializatio logger.LogDebug("the typedFeature Json property was not found in the FeatureTyping: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.FeatureTyping dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 FeatureTyping: { 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 FeatureTyping: { 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 FeatureTyping: { 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 FeatureTyping: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the FeatureTyping: { 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 FeatureTyping: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the FeatureTyping: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the FeatureTyping: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the FeatureTyping: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the FeatureTyping: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("type"u8, out var typeProperty)) + { + if (typeProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.Type = Guid.Empty; + logger.LogDebug($"the FeatureTyping.Type property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (typeProperty.TryGetProperty("@id"u8, out var typeExternalIdProperty)) + { + var propertyValue = typeExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Type = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the type Json property was not found in the FeatureTyping: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("typedFeature"u8, out var typedFeatureProperty)) + { + if (typedFeatureProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.TypedFeature = Guid.Empty; + logger.LogDebug($"the FeatureTyping.TypedFeature property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (typedFeatureProperty.TryGetProperty("@id"u8, out var typedFeatureExternalIdProperty)) + { + var propertyValue = typedFeatureExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.TypedFeature = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the typedFeature Json property was not found in the FeatureTyping: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/FlowDeSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/FlowDeSerializer.cs index 18274448..4e3d0852 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/FlowDeSerializer.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/FlowDeSerializer.cs @@ -49,13 +49,16 @@ internal static class FlowDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IFlow DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IFlow DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("FlowDeSerializer"); @@ -85,6 +88,33 @@ internal static IFlow DeSerialize(JsonElement jsonElement, SerializationModeKind } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Interactions.Flow dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1675,8 +1705,313 @@ internal static IFlow DeSerialize(JsonElement jsonElement, SerializationModeKind logger.LogDebug("the unioningType Json property was not found in the Flow: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Interactions.Flow dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Flow: { 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 Flow: { 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 Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the Flow: { 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 Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Flow: { 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 Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Flow: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Flow: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/FramedConcernMembershipDeSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/FramedConcernMembershipDeSerializer.cs index e6ed1845..4a85eda1 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/FramedConcernMembershipDeSerializer.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/FramedConcernMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class FramedConcernMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IFramedConcernMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IFramedConcernMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("FramedConcernMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IFramedConcernMembership DeSerialize(JsonElement jsonElement, Se } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.FramedConcernMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -582,8 +612,202 @@ internal static IFramedConcernMembership DeSerialize(JsonElement jsonElement, Se logger.LogDebug("the visibility Json property was not found in the FramedConcernMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.FramedConcernMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 FramedConcernMembership: { 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 FramedConcernMembership: { 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 FramedConcernMembership: { 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 FramedConcernMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the FramedConcernMembership: { 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 FramedConcernMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("kind"u8, out var kindProperty)) + { + dtoInstance.Kind = RequirementConstraintKindDeSerializer.Deserialize(kindProperty.GetString()); + } + else + { + logger.LogDebug("the kind Json property was not found in the FramedConcernMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the FramedConcernMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the FramedConcernMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the FramedConcernMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the FramedConcernMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the FramedConcernMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/LiteralIntegerDeSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/LiteralIntegerDeSerializer.cs index a233bc5f..429868b9 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/LiteralIntegerDeSerializer.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/LiteralIntegerDeSerializer.cs @@ -49,13 +49,16 @@ internal static class LiteralIntegerDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ILiteralInteger DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ILiteralInteger DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("LiteralIntegerDeSerializer"); @@ -85,6 +88,33 @@ internal static ILiteralInteger DeSerialize(JsonElement jsonElement, Serializati } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.LiteralInteger dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1489,8 +1519,266 @@ internal static ILiteralInteger DeSerialize(JsonElement jsonElement, Serializati logger.LogDebug("the value Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.LiteralInteger dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 LiteralInteger: { 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 LiteralInteger: { 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 LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the LiteralInteger: { 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 LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the LiteralInteger: { 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 LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the LiteralInteger: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) + { + dtoInstance.Value = valueProperty.GetInt32(); + } + else + { + logger.LogDebug("the value Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/LiteralRationalDeSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/LiteralRationalDeSerializer.cs index 7d656cdb..957f45fa 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/LiteralRationalDeSerializer.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/LiteralRationalDeSerializer.cs @@ -49,13 +49,16 @@ internal static class LiteralRationalDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ILiteralRational DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ILiteralRational DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("LiteralRationalDeSerializer"); @@ -85,6 +88,33 @@ internal static ILiteralRational DeSerialize(JsonElement jsonElement, Serializat } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.LiteralRational dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1489,8 +1519,266 @@ internal static ILiteralRational DeSerialize(JsonElement jsonElement, Serializat logger.LogDebug("the value Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.LiteralRational dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 LiteralRational: { 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 LiteralRational: { 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 LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the LiteralRational: { 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 LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the LiteralRational: { 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 LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the LiteralRational: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) + { + dtoInstance.Value = valueProperty.GetDouble(); + } + else + { + logger.LogDebug("the value Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/MembershipDeSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/MembershipDeSerializer.cs index 5ab23a1b..b41eb66c 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/MembershipDeSerializer.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/MembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class MembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("MembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IMembership DeSerialize(JsonElement jsonElement, SerializationMo } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Root.Namespaces.Membership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -548,8 +578,236 @@ internal static IMembership DeSerialize(JsonElement jsonElement, SerializationMo logger.LogDebug("the visibility Json property was not found in the Membership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Root.Namespaces.Membership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Membership: { 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 Membership: { 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 Membership: { 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 Membership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Membership: { 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 Membership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("memberElement"u8, out var memberElementProperty)) + { + if (memberElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.MemberElement = Guid.Empty; + logger.LogDebug($"the Membership.MemberElement property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (memberElementProperty.TryGetProperty("@id"u8, out var memberElementExternalIdProperty)) + { + var propertyValue = memberElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.MemberElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the memberElement Json property was not found in the Membership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("memberName"u8, out var memberNameProperty)) + { + dtoInstance.MemberName = memberNameProperty.GetString(); + } + else + { + logger.LogDebug("the memberName Json property was not found in the Membership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("memberShortName"u8, out var memberShortNameProperty)) + { + dtoInstance.MemberShortName = memberShortNameProperty.GetString(); + } + else + { + logger.LogDebug("the memberShortName Json property was not found in the Membership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Membership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Membership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Membership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Membership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the Membership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/MultiplicityRangeDeSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/MultiplicityRangeDeSerializer.cs index 14804ba3..5dafccd7 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/MultiplicityRangeDeSerializer.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/MultiplicityRangeDeSerializer.cs @@ -49,13 +49,16 @@ internal static class MultiplicityRangeDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IMultiplicityRange DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IMultiplicityRange DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("MultiplicityRangeDeSerializer"); @@ -85,6 +88,33 @@ internal static IMultiplicityRange DeSerialize(JsonElement jsonElement, Serializ } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Multiplicities.MultiplicityRange dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1488,8 +1518,257 @@ internal static IMultiplicityRange DeSerialize(JsonElement jsonElement, Serializ logger.LogDebug("the upperBound Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Multiplicities.MultiplicityRange dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 MultiplicityRange: { 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 MultiplicityRange: { 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 MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the MultiplicityRange: { 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 MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the MultiplicityRange: { 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 MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the MultiplicityRange: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/OwningMembershipDeSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/OwningMembershipDeSerializer.cs index 2418ccc2..0c43646c 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/OwningMembershipDeSerializer.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/OwningMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class OwningMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IOwningMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IOwningMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("OwningMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IOwningMembership DeSerialize(JsonElement jsonElement, Serializa } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Root.Namespaces.OwningMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -548,8 +578,193 @@ internal static IOwningMembership DeSerialize(JsonElement jsonElement, Serializa logger.LogDebug("the visibility Json property was not found in the OwningMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Root.Namespaces.OwningMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 OwningMembership: { 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 OwningMembership: { 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 OwningMembership: { 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 OwningMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the OwningMembership: { 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 OwningMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the OwningMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the OwningMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the OwningMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the OwningMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the OwningMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/ReferenceSubsettingDeSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/ReferenceSubsettingDeSerializer.cs index dbb3051c..1ffc74ad 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/ReferenceSubsettingDeSerializer.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/ReferenceSubsettingDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ReferenceSubsettingDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IReferenceSubsetting DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IReferenceSubsetting DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ReferenceSubsettingDeSerializer"); @@ -85,6 +88,33 @@ internal static IReferenceSubsetting DeSerialize(JsonElement jsonElement, Serial } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.ReferenceSubsetting dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -507,8 +537,209 @@ internal static IReferenceSubsetting DeSerialize(JsonElement jsonElement, Serial logger.LogDebug("the textualRepresentation Json property was not found in the ReferenceSubsetting: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.ReferenceSubsetting dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ReferenceSubsetting: { 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 ReferenceSubsetting: { 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 ReferenceSubsetting: { 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 ReferenceSubsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the ReferenceSubsetting: { 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 ReferenceSubsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the ReferenceSubsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ReferenceSubsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the ReferenceSubsetting: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ReferenceSubsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("referencedFeature"u8, out var referencedFeatureProperty)) + { + if (referencedFeatureProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.ReferencedFeature = Guid.Empty; + logger.LogDebug($"the ReferenceSubsetting.ReferencedFeature property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (referencedFeatureProperty.TryGetProperty("@id"u8, out var referencedFeatureExternalIdProperty)) + { + var propertyValue = referencedFeatureExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.ReferencedFeature = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the referencedFeature Json property was not found in the ReferenceSubsetting: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/RequirementUsageDeSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/RequirementUsageDeSerializer.cs index 9d611404..aa2e702b 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/RequirementUsageDeSerializer.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/RequirementUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class RequirementUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IRequirementUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IRequirementUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("RequirementUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IRequirementUsage DeSerialize(JsonElement jsonElement, Serializa } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.RequirementUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actorParameter"u8, out var actorParameterProperty)) { foreach (var arrayItem in actorParameterProperty.EnumerateArray()) @@ -2359,8 +2389,278 @@ internal static IRequirementUsage DeSerialize(JsonElement jsonElement, Serializa logger.LogDebug("the variantMembership Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.RequirementUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 RequirementUsage: { 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 RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the RequirementUsage: { 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 RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the RequirementUsage: { 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 RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the RequirementUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("reqId"u8, out var reqIdProperty)) + { + dtoInstance.ReqId = reqIdProperty.GetString(); + } + else + { + logger.LogDebug("the reqId Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/SelectExpressionDeSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/SelectExpressionDeSerializer.cs index 8c524c31..700a71bc 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/SelectExpressionDeSerializer.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/SelectExpressionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class SelectExpressionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ISelectExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ISelectExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("SelectExpressionDeSerializer"); @@ -85,6 +88,33 @@ internal static ISelectExpression DeSerialize(JsonElement jsonElement, Serializa } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.SelectExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1539,8 +1569,271 @@ internal static ISelectExpression DeSerialize(JsonElement jsonElement, Serializa logger.LogDebug("the unioningType Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.SelectExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 SelectExpression: { 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 SelectExpression: { 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 SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the SelectExpression: { 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 SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the SelectExpression: { 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 SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("operator"u8, out var operatorProperty)) + { + var propertyValue = operatorProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Operator = propertyValue; + } + } + else + { + logger.LogDebug("the operator Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the SelectExpression: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/SubclassificationDeSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/SubclassificationDeSerializer.cs index 08b87b06..822a93c1 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/SubclassificationDeSerializer.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/SubclassificationDeSerializer.cs @@ -49,13 +49,16 @@ internal static class SubclassificationDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ISubclassification DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ISubclassification DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("SubclassificationDeSerializer"); @@ -85,6 +88,33 @@ internal static ISubclassification DeSerialize(JsonElement jsonElement, Serializ } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Classifiers.Subclassification dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -531,8 +561,234 @@ internal static ISubclassification DeSerialize(JsonElement jsonElement, Serializ logger.LogDebug("the textualRepresentation Json property was not found in the Subclassification: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Classifiers.Subclassification dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Subclassification: { 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 Subclassification: { 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 Subclassification: { 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 Subclassification: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Subclassification: { 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 Subclassification: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Subclassification: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Subclassification: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Subclassification: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Subclassification: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("subclassifier"u8, out var subclassifierProperty)) + { + if (subclassifierProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.Subclassifier = Guid.Empty; + logger.LogDebug($"the Subclassification.Subclassifier property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (subclassifierProperty.TryGetProperty("@id"u8, out var subclassifierExternalIdProperty)) + { + var propertyValue = subclassifierExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Subclassifier = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the subclassifier Json property was not found in the Subclassification: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("superclassifier"u8, out var superclassifierProperty)) + { + if (superclassifierProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.Superclassifier = Guid.Empty; + logger.LogDebug($"the Subclassification.Superclassifier property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (superclassifierProperty.TryGetProperty("@id"u8, out var superclassifierExternalIdProperty)) + { + var propertyValue = superclassifierExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Superclassifier = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the superclassifier Json property was not found in the Subclassification: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/TextualRepresentationDeSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/TextualRepresentationDeSerializer.cs index 6111bc8f..d3323b06 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/TextualRepresentationDeSerializer.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/TextualRepresentationDeSerializer.cs @@ -49,13 +49,16 @@ internal static class TextualRepresentationDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ITextualRepresentation DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ITextualRepresentation DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("TextualRepresentationDeSerializer"); @@ -85,6 +88,33 @@ internal static ITextualRepresentation DeSerialize(JsonElement jsonElement, Seri } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Root.Annotations.TextualRepresentation dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -498,8 +528,156 @@ internal static ITextualRepresentation DeSerialize(JsonElement jsonElement, Seri logger.LogDebug("the textualRepresentation Json property was not found in the TextualRepresentation: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Root.Annotations.TextualRepresentation dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 TextualRepresentation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("body"u8, out var bodyProperty)) + { + var propertyValue = bodyProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Body = propertyValue; + } + } + else + { + logger.LogDebug("the body Json property was not found in the TextualRepresentation: { 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 TextualRepresentation: { 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 TextualRepresentation: { 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 TextualRepresentation: { 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 TextualRepresentation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("language"u8, out var languageProperty)) + { + var propertyValue = languageProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Language = propertyValue; + } + } + else + { + logger.LogDebug("the language Json property was not found in the TextualRepresentation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the TextualRepresentation: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the TextualRepresentation: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/UsageDeSerializer.cs b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/UsageDeSerializer.cs index 2e6c3e65..a80de28a 100644 --- a/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/UsageDeSerializer.cs +++ b/SysML2.NET.CodeGenerator.Tests/Expected/UML/Core/AutoGenDeSerializer/UsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class UsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("UsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IUsage DeSerialize(JsonElement jsonElement, SerializationModeKin } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.DefinitionAndUsage.Usage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2111,8 +2141,257 @@ internal static IUsage DeSerialize(JsonElement jsonElement, SerializationModeKin logger.LogDebug("the variantMembership Json property was not found in the Usage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.DefinitionAndUsage.Usage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Usage: { 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 Usage: { 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 Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the Usage: { 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 Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the Usage: { 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 Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Usage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Usage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.CodeGenerator/Templates/Uml/core-json-dto-deserialization-provider-uml-template.hbs b/SysML2.NET.CodeGenerator/Templates/Uml/core-json-dto-deserialization-provider-uml-template.hbs index c8b44fb2..be44486a 100644 --- a/SysML2.NET.CodeGenerator/Templates/Uml/core-json-dto-deserialization-provider-uml-template.hbs +++ b/SysML2.NET.CodeGenerator/Templates/Uml/core-json-dto-deserialization-provider-uml-template.hbs @@ -41,7 +41,7 @@ namespace SysML2.NET.Serializer.Json.Core.DTO /// /// a dictionary that provides delegates for deserialization /// - private static readonly Dictionary> DeSerializerActionMap = new Dictionary> + private static readonly Dictionary> DeSerializerActionMap = new Dictionary> { {{#each this as | class |}} { "{{ class.Name }}", {{ class.Name }}DeSerializer.DeSerialize }, @@ -49,19 +49,19 @@ namespace SysML2.NET.Serializer.Json.Core.DTO }; /// - /// Provides the delegate for the + /// Provides the delegate for the /// that is to be deserialized /// /// /// The name of the subject that is to be serialized /// /// - /// A Delegate of + /// A Delegate of /// /// /// Thrown when the is not supported. /// - internal static Func Provide(string typeName) + internal static Func Provide(string typeName) { if (!DeSerializerActionMap.TryGetValue(typeName, out var func)) { diff --git a/SysML2.NET.CodeGenerator/Templates/Uml/core-json-dto-deserializer-uml-template.hbs b/SysML2.NET.CodeGenerator/Templates/Uml/core-json-dto-deserializer-uml-template.hbs index 69834029..76346a7f 100644 --- a/SysML2.NET.CodeGenerator/Templates/Uml/core-json-dto-deserializer-uml-template.hbs +++ b/SysML2.NET.CodeGenerator/Templates/Uml/core-json-dto-deserializer-uml-template.hbs @@ -49,13 +49,16 @@ namespace SysML2.NET.Serializer.Json.Core.DTO /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static I{{ this.Name }} DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static I{{ this.Name }} DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("{{ this.Name }}DeSerializer"); @@ -85,133 +88,302 @@ namespace SysML2.NET.Serializer.Json.Core.DTO } } + if(deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.{{ #NamedElement.WriteFullyQualifiedNameSpace this }}.{{ this.Name }} dtoInstance, JsonElement jsonElement, ILogger logger) + { {{#with this as |class| }} {{ #each (Class.QueryAllProperties this) as | property | }} - {{#unless this.IsTransient}} - {{#unless (Property.IsPropertyRedefinedInClass this class)}} - if (jsonElement.TryGetProperty("{{ property.Name }}"u8, out var {{ property.Name }}Property)) - { - {{#if (Property.QueryIsReferenceProperty property)}} - {{#if (Property.QueryIsEnumerable property)}} - foreach (var arrayItem in {{ property.Name }}Property.EnumerateArray()) + {{#unless this.IsTransient}} + {{#unless (Property.IsPropertyRedefinedInClass this class)}} + if (jsonElement.TryGetProperty("{{ property.Name }}"u8, out var {{ property.Name }}Property)) + { + {{#if (Property.QueryIsReferenceProperty property)}} + {{#if (Property.QueryIsEnumerable property)}} + foreach (var arrayItem in {{ property.Name }}Property.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var {{ property.Name }}ExternalIdProperty)) + { + var propertyValue = {{ property.Name }}ExternalIdProperty.GetString(); + + if (propertyValue != null) + { + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }}.Add(Guid.Parse(propertyValue)); + } + } + } + {{ else }} + if ({{ property.Name }}Property.ValueKind == JsonValueKind.Null) + { + {{#if (Property.QueryIsNullable property) }} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = null; + {{else}} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = Guid.Empty; + logger.LogDebug($"the {{ class.Name }}.{{Property.WritePropertyName property}} property was not found in the Json. The value is set to Guid.Empty"); + {{/if}} + } + else + { + if ({{ property.Name }}Property.TryGetProperty("@id"u8, out var {{ property.Name }}ExternalIdProperty)) + { + var propertyValue = {{ property.Name }}ExternalIdProperty.GetString(); + + if (propertyValue != null) + { + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = Guid.Parse(propertyValue); + } + } + } + {{/if}} + {{ else }} + {{#if (Property.QueryIsEnumerable property)}} + foreach (var arrayItem in {{ property.Name }}Property.EnumerateArray()) + { + {{#if (Property.QueryIsBool property )}} + var propertyValue = arrayItem.GetBoolean(); + + if (propertyValue != null) { - if (arrayItem.TryGetProperty("@id"u8, out var {{ property.Name }}ExternalIdProperty)) - { - var propertyValue = {{ property.Name }}ExternalIdProperty.GetString(); - - if (propertyValue != null) - { - {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }}.Add(Guid.Parse(propertyValue)); - } - } + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }}.Add(propertyValue); } - {{ else }} - if ({{ property.Name }}Property.ValueKind == JsonValueKind.Null) - { - {{#if (Property.QueryIsNullable property) }} - {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = null; - {{else}} - {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = Guid.Empty; - logger.LogDebug($"the {{ class.Name }}.{{Property.WritePropertyName property}} property was not found in the Json. The value is set to Guid.Empty"); + {{else if (Property.QueryIsEnum property )}} + throw new NotImplementedException("Enumerable Enum - {{class.Name}}.{{property.Name}} is not yet supported"); + {{else if (Property.QueryIsNumeric property )}} + {{#if (Property.QueryIsInteger property) }} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }}.Add(arrayItem.GetInt32()); + {{else if (Property.QueryIsDouble property) }} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }}.Add(arrayItem.GetDouble()); + {{ else }} + throw new NotImplementedException("Enumerable Double - {{class.Name}}.{{property.Name}} is not yet supported"); {{/if}} - } - else + {{else}} + var propertyValue = arrayItem.GetString(); + + if (propertyValue != null) { - if ({{ property.Name }}Property.TryGetProperty("@id"u8, out var {{ property.Name }}ExternalIdProperty)) - { - var propertyValue = {{ property.Name }}ExternalIdProperty.GetString(); - - if (propertyValue != null) - { - {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = Guid.Parse(propertyValue); - } - } + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }}.Add(propertyValue); } {{/if}} - {{ else }} - {{#if (Property.QueryIsEnumerable property)}} - foreach (var arrayItem in {{ property.Name }}Property.EnumerateArray()) - { - {{#if (Property.QueryIsBool property )}} - var propertyValue = arrayItem.GetBoolean(); - - if (propertyValue != null) - { - {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }}.Add(propertyValue); - } - {{else if (Property.QueryIsEnum property )}} - throw new NotImplementedException("Enumerable Enum - {{class.Name}}.{{property.Name}} is not yet supported"); - {{else if (Property.QueryIsNumeric property )}} - {{#if (Property.QueryIsInteger property) }} - {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }}.Add(arrayItem.GetInt32()); - {{else if (Property.QueryIsDouble property) }} - {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }}.Add(arrayItem.GetDouble()); - {{ else }} - throw new NotImplementedException("Enumerable Double - {{class.Name}}.{{property.Name}} is not yet supported"); - {{/if}} - {{else}} - var propertyValue = arrayItem.GetString(); - - if (propertyValue != null) - { - {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }}.Add(propertyValue); - } + } + {{ else if (Property.QueryIsNullable property) }} + {{#if (Property.QueryIsBool property )}} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetBoolean(); + {{else if (Property.QueryIsEnum property )}} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Type.Name }}DeSerializer.DeserializeNullable({{ property.Name }}Property.GetString()); + {{else if (Property.QueryIsNumeric property )}} + {{#if (Property.QueryIsInteger property) }} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetInt32(); + {{else if (Property.QueryIsDouble property) }} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetDouble(); + {{ else }} + new NotImplementedException("nullable - {{class.Name}}.{{property.Name}} is not yet supported"); {{/if}} + {{else}} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetString(); + {{/if}} + {{ else if (Property.QueryIsScalar property) }} + {{#if (Property.QueryIsBool property )}} + if ({{ property.Name }}Property.ValueKind != JsonValueKind.Null) + { + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetBoolean(); } - {{ else if (Property.QueryIsNullable property) }} - {{#if (Property.QueryIsBool property )}} - {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetBoolean(); - {{else if (Property.QueryIsEnum property )}} - {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Type.Name }}DeSerializer.DeserializeNullable({{ property.Name }}Property.GetString()); - {{else if (Property.QueryIsNumeric property )}} - {{#if (Property.QueryIsInteger property) }} - {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetInt32(); - {{else if (Property.QueryIsDouble property) }} - {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetDouble(); - {{ else }} - new NotImplementedException("nullable - {{class.Name}}.{{property.Name}} is not yet supported"); - {{/if}} - {{else}} - {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetString(); - {{/if}} - {{ else if (Property.QueryIsScalar property) }} - {{#if (Property.QueryIsBool property )}} - if ({{ property.Name }}Property.ValueKind != JsonValueKind.Null) - { - {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetBoolean(); - } - {{else if (Property.QueryIsEnum property )}} - {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Type.Name }}DeSerializer.Deserialize({{ property.Name }}Property.GetString()); - {{else if (Property.QueryIsNumeric property )}} - {{#if (Property.QueryIsInteger property) }} - {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetInt32(); - {{else if (Property.QueryIsDouble property) }} - {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetDouble(); - {{ else }} - new NotImplementedException("Scalar - {{class.Name}}.{{property.Name}} is not yet supported"); - {{/if}} - {{else}} - var propertyValue = {{property.Name }}Property.GetString(); - - if (propertyValue != null) - { - {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = propertyValue; - } + {{else if (Property.QueryIsEnum property )}} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Type.Name }}DeSerializer.Deserialize({{ property.Name }}Property.GetString()); + {{else if (Property.QueryIsNumeric property )}} + {{#if (Property.QueryIsInteger property) }} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetInt32(); + {{else if (Property.QueryIsDouble property) }} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetDouble(); + {{ else }} + new NotImplementedException("Scalar - {{class.Name}}.{{property.Name}} is not yet supported"); {{/if}} + {{else}} + var propertyValue = {{property.Name }}Property.GetString(); + + if (propertyValue != null) + { + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = propertyValue; + } {{/if}} {{/if}} + {{/if}} + } + else + { + logger.LogDebug("the {{ property.Name }} Json property was not found in the {{ class.Name }}: { Id }", dtoInstance.Id); + } + + {{/unless}} + {{/unless}} + {{/each}} + {{/with}} + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.{{ #NamedElement.WriteFullyQualifiedNameSpace this }}.{{ this.Name }} dtoInstance, JsonElement jsonElement, ILogger logger) + { + {{#with this as |class| }} + {{ #each (Class.QueryAllProperties this) as | property | }} + {{#unless this.IsTransient}} + {{#unless this.IsDerived}} + {{#unless (Property.IsPropertyRedefinedInClass this class)}} + if (jsonElement.TryGetProperty("{{ property.Name }}"u8, out var {{ property.Name }}Property)) + { + {{#if (Property.QueryIsReferenceProperty property)}} + {{#if (Property.QueryIsEnumerable property)}} + foreach (var arrayItem in {{ property.Name }}Property.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var {{ property.Name }}ExternalIdProperty)) + { + var propertyValue = {{ property.Name }}ExternalIdProperty.GetString(); + + if (propertyValue != null) + { + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }}.Add(Guid.Parse(propertyValue)); + } + } + } + {{ else }} + if ({{ property.Name }}Property.ValueKind == JsonValueKind.Null) + { + {{#if (Property.QueryIsNullable property) }} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = null; + {{else}} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = Guid.Empty; + logger.LogDebug($"the {{ class.Name }}.{{Property.WritePropertyName property}} property was not found in the Json. The value is set to Guid.Empty"); + {{/if}} } else { - logger.LogDebug("the {{ property.Name }} Json property was not found in the {{ class.Name }}: { Id }", dtoInstance.Id); + if ({{ property.Name }}Property.TryGetProperty("@id"u8, out var {{ property.Name }}ExternalIdProperty)) + { + var propertyValue = {{ property.Name }}ExternalIdProperty.GetString(); + + if (propertyValue != null) + { + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = Guid.Parse(propertyValue); } - - {{/unless}} - {{/unless}} - {{/each}} - {{/with}} + } + } + {{/if}} + {{ else }} + {{#if (Property.QueryIsEnumerable property)}} + foreach (var arrayItem in {{ property.Name }}Property.EnumerateArray()) + { + {{#if (Property.QueryIsBool property )}} + var propertyValue = arrayItem.GetBoolean(); - return dtoInstance; + if (propertyValue != null) + { + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }}.Add(propertyValue); + } + {{else if (Property.QueryIsEnum property )}} + throw new NotImplementedException("Enumerable Enum - {{class.Name}}.{{property.Name}} is not yet supported"); + {{else if (Property.QueryIsNumeric property )}} + {{#if (Property.QueryIsInteger property) }} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }}.Add(arrayItem.GetInt32()); + {{else if (Property.QueryIsDouble property) }} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }}.Add(arrayItem.GetDouble()); + {{ else }} + throw new NotImplementedException("Enumerable Double - {{class.Name}}.{{property.Name}} is not yet supported"); + {{/if}} + {{else}} + var propertyValue = arrayItem.GetString(); + + if (propertyValue != null) + { + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }}.Add(propertyValue); + } + {{/if}} + } + {{ else if (Property.QueryIsNullable property) }} + {{#if (Property.QueryIsBool property )}} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetBoolean(); + {{else if (Property.QueryIsEnum property )}} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Type.Name }}DeSerializer.DeserializeNullable({{ property.Name }}Property.GetString()); + {{else if (Property.QueryIsNumeric property )}} + {{#if (Property.QueryIsInteger property) }} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetInt32(); + {{else if (Property.QueryIsDouble property) }} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetDouble(); + {{ else }} + new NotImplementedException("nullable - {{class.Name}}.{{property.Name}} is not yet supported"); + {{/if}} + {{else}} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetString(); + {{/if}} + {{ else if (Property.QueryIsScalar property) }} + {{#if (Property.QueryIsBool property )}} + if ({{ property.Name }}Property.ValueKind != JsonValueKind.Null) + { + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetBoolean(); + } + {{else if (Property.QueryIsEnum property )}} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Type.Name }}DeSerializer.Deserialize({{ property.Name }}Property.GetString()); + {{else if (Property.QueryIsNumeric property )}} + {{#if (Property.QueryIsInteger property) }} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetInt32(); + {{else if (Property.QueryIsDouble property) }} + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = {{ property.Name }}Property.GetDouble(); + {{ else }} + new NotImplementedException("Scalar - {{class.Name}}.{{property.Name}} is not yet supported"); + {{/if}} + {{else}} + var propertyValue = {{property.Name }}Property.GetString(); + + if (propertyValue != null) + { + {{ #Property.WritePropertyWithExplicitInterfaceIfRequiredForDTO property class dtoInstance }} = propertyValue; + } + {{/if}} + {{/if}} + {{/if}} + } + else + { + logger.LogDebug("the {{ property.Name }} Json property was not found in the {{ class.Name }}: { Id }", dtoInstance.Id); + } + + {{/unless}} + {{/unless}} + {{/unless}} + {{/each}} +{{/with}} } } } diff --git a/SysML2.NET.Serializer.Json.Tests/DeSerializerTestFixture.cs b/SysML2.NET.Serializer.Json.Tests/DeSerializerTestFixture.cs index e04c8178..09d1df10 100644 --- a/SysML2.NET.Serializer.Json.Tests/DeSerializerTestFixture.cs +++ b/SysML2.NET.Serializer.Json.Tests/DeSerializerTestFixture.cs @@ -50,19 +50,25 @@ public void SetUp() } [Test] - public void Verify_that_idada_from_sysmlcore_json_can_be_deserialized() + [TestCase(false)] + [TestCase(true)] + public void Verify_that_idada_from_sysmlcore_json_can_be_deserialized(bool shouldDeserializeDerivedProperties) { var fileName = Path.Combine(TestContext.CurrentContext.WorkDirectory, "Data", "projects.000e9890-6935-43e6-a5d7-5d7cac601f4c.commits.6d7ad9fd-6520-4ff2-885b-8c5c129e6c27.elements.json"); - using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) - { - var data = this.deSerializer.DeSerialize(stream, SerializationModeKind.JSON, SerializationTargetKind.CORE); + using var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); - Assert.That(data.Count(), Is.EqualTo(100)); + var data = this.deSerializer.DeSerialize(stream, SerializationModeKind.JSON, SerializationTargetKind.CORE, shouldDeserializeDerivedProperties); + using (Assert.EnterMultipleScope()) + { + Assert.That(data.Count(), Is.EqualTo(100)); Assert.That(data.OfType().Count(), Is.EqualTo(30)); + } - var feature = data.OfType().Single(x => x.Id == Guid.Parse("00a6ef10-d3dc-4741-9029-2c9978c2f083")); + var feature = data.OfType().Single(x => x.Id == Guid.Parse("00a6ef10-d3dc-4741-9029-2c9978c2f083")); + using (Assert.EnterMultipleScope()) + { Assert.That(feature.AliasIds, Is.Empty); Assert.That(feature.ElementId, Is.EqualTo("00a6ef10-d3dc-4741-9029-2c9978c2f083")); Assert.That(feature.IsAbstract, Is.False); @@ -79,21 +85,29 @@ public void Verify_that_idada_from_sysmlcore_json_can_be_deserialized() } [Test] - public async Task Verify_that_idada_from_sysmlcore_json_can_be_deserialized_async() + [TestCase(false)] + [TestCase(true)] + public async Task Verify_that_idada_from_sysmlcore_json_can_be_deserialized_async(bool shouldDeserializeDerivedProperties) { var fileName = Path.Combine(TestContext.CurrentContext.WorkDirectory, "Data", "projects.000e9890-6935-43e6-a5d7-5d7cac601f4c.commits.6d7ad9fd-6520-4ff2-885b-8c5c129e6c27.elements.json"); - using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) - { - var cts = new CancellationTokenSource(); - var data = await this.deSerializer.DeSerializeAsync(stream, SerializationModeKind.JSON, SerializationTargetKind.CORE, cts.Token); + await using var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); + + var cts = new CancellationTokenSource(); + var data = await this.deSerializer.DeSerializeAsync(stream, SerializationModeKind.JSON, SerializationTargetKind.CORE, shouldDeserializeDerivedProperties, cts.Token); + + using (Assert.EnterMultipleScope()) + { Assert.That(data.Count(), Is.EqualTo(100)); Assert.That(data.OfType().Count(), Is.EqualTo(30)); + } - var feature = data.OfType().Single(x => x.Id == Guid.Parse("00a6ef10-d3dc-4741-9029-2c9978c2f083")); + var feature = data.OfType().Single(x => x.Id == Guid.Parse("00a6ef10-d3dc-4741-9029-2c9978c2f083")); + using (Assert.EnterMultipleScope()) + { Assert.That(feature.AliasIds, Is.Empty); Assert.That(feature.ElementId, Is.EqualTo("00a6ef10-d3dc-4741-9029-2c9978c2f083")); Assert.That(feature.IsAbstract, Is.False); @@ -110,17 +124,21 @@ public async Task Verify_that_idada_from_sysmlcore_json_can_be_deserialized_asyn } [Test] - public void Verify_that_projects_from_restapi_json_can_be_deserialized() + [TestCase(false)] + [TestCase(true)] + public void Verify_that_projects_from_restapi_json_can_be_deserialized(bool shouldDeserializeDerivedProperties) { var fileName = Path.Combine(TestContext.CurrentContext.WorkDirectory, "Data", "projects.json"); - using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) - { - var data = this.deSerializer.DeSerialize(stream, SerializationModeKind.JSON, SerializationTargetKind.PSM); + using var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); + + var data = this.deSerializer.DeSerialize(stream, SerializationModeKind.JSON, SerializationTargetKind.PSM, shouldDeserializeDerivedProperties); - Assert.That(data.Count(), Is.EqualTo(43)); + Assert.That(data.Count(), Is.EqualTo(43)); - var project = data.OfType().Single(x => x.Id == Guid.Parse("000e9890-6935-43e6-a5d7-5d7cac601f4c")); + var project = data.OfType().Single(x => x.Id == Guid.Parse("000e9890-6935-43e6-a5d7-5d7cac601f4c")); + using (Assert.EnterMultipleScope()) + { Assert.That(project.DefaultBranch, Is.EqualTo(Guid.Parse("c294a463-6c9c-47a8-b592-01252c5ab2a7"))); Assert.That(project.Name, Is.EqualTo("7b-Variant Configurations Mon Mar 13 17:54:29 EDT 2023")); Assert.That(project.Description, Is.Null); @@ -128,17 +146,21 @@ public void Verify_that_projects_from_restapi_json_can_be_deserialized() } [Test] - public void Verify_that_particular_project_from_restapi_json_can_be_deserialized() + [TestCase(false)] + [TestCase(true)] + public void Verify_that_particular_project_from_restapi_json_can_be_deserialized(bool shouldDeserializeDerivedProperties) { var fileName = Path.Combine(TestContext.CurrentContext.WorkDirectory, "Data", "projects.000e9890-6935-43e6-a5d7-5d7cac601f4c.json"); - using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) - { - var data = this.deSerializer.DeSerialize(stream, SerializationModeKind.JSON, SerializationTargetKind.PSM); + using var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); + + var data = this.deSerializer.DeSerialize(stream, SerializationModeKind.JSON, SerializationTargetKind.PSM, shouldDeserializeDerivedProperties); - Assert.That(data.Count(), Is.EqualTo(1)); + Assert.That(data.Count(), Is.EqualTo(1)); - var project = data.OfType().Single(x => x.Id == Guid.Parse("000e9890-6935-43e6-a5d7-5d7cac601f4c")); + var project = data.OfType().Single(x => x.Id == Guid.Parse("000e9890-6935-43e6-a5d7-5d7cac601f4c")); + using (Assert.EnterMultipleScope()) + { Assert.That(project.DefaultBranch, Is.EqualTo(Guid.Parse("c294a463-6c9c-47a8-b592-01252c5ab2a7"))); Assert.That(project.Name, Is.EqualTo("7b-Variant Configurations Mon Mar 13 17:54:29 EDT 2023")); Assert.That(project.Description, Is.Null); @@ -146,16 +168,21 @@ public void Verify_that_particular_project_from_restapi_json_can_be_deserialized } [Test] - public void Verify_that_particular_project_and_commits_from_restapi_json_can_be_deserialized() + [TestCase(false)] + [TestCase(true)] + public void Verify_that_particular_project_and_commits_from_restapi_json_can_be_deserialized(bool shouldDeserializeDerivedProperties) { var fileName = Path.Combine(TestContext.CurrentContext.WorkDirectory, "Data", "projects.000e9890-6935-43e6-a5d7-5d7cac601f4c.commits.json"); - using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) - { - var data = this.deSerializer.DeSerialize(stream, SerializationModeKind.JSON, SerializationTargetKind.PSM); + using var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); - Assert.That(data.Count(), Is.EqualTo(1)); + var data = this.deSerializer.DeSerialize(stream, SerializationModeKind.JSON, SerializationTargetKind.PSM, shouldDeserializeDerivedProperties); - var firstCommit = data.OfType().Single(x => x.Id == Guid.Parse("6d7ad9fd-6520-4ff2-885b-8c5c129e6c27")); + Assert.That(data.Count(), Is.EqualTo(1)); + + var firstCommit = data.OfType().Single(x => x.Id == Guid.Parse("6d7ad9fd-6520-4ff2-885b-8c5c129e6c27")); + + using (Assert.EnterMultipleScope()) + { Assert.That(firstCommit.OwningProject, Is.EqualTo(Guid.Parse("000e9890-6935-43e6-a5d7-5d7cac601f4c"))); Assert.That(firstCommit.PreviousCommit, Is.EqualTo(Guid.Empty)); Assert.That(firstCommit.Description, Is.Null); @@ -164,16 +191,21 @@ public void Verify_that_particular_project_and_commits_from_restapi_json_can_be_ } [Test] - public void Verify_that_particular_project_and_particular_commit_from_restapi_json_can_be_deserialized() + [TestCase(false)] + [TestCase(true)] + public void Verify_that_particular_project_and_particular_commit_from_restapi_json_can_be_deserialized(bool shouldDeserializeDerivedProperties) { var fileName = Path.Combine(TestContext.CurrentContext.WorkDirectory, "Data", "projects.000e9890-6935-43e6-a5d7-5d7cac601f4c.commits.6d7ad9fd-6520-4ff2-885b-8c5c129e6c27.json"); - using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) - { - var data = this.deSerializer.DeSerialize(stream, SerializationModeKind.JSON, SerializationTargetKind.PSM); + using var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); - Assert.That(data.Count(), Is.EqualTo(1)); + var data = this.deSerializer.DeSerialize(stream, SerializationModeKind.JSON, SerializationTargetKind.PSM, shouldDeserializeDerivedProperties); - var firstCommit = data.OfType().Single(x => x.Id == Guid.Parse("6d7ad9fd-6520-4ff2-885b-8c5c129e6c27")); + Assert.That(data.Count(), Is.EqualTo(1)); + + var firstCommit = data.OfType().Single(x => x.Id == Guid.Parse("6d7ad9fd-6520-4ff2-885b-8c5c129e6c27")); + + using (Assert.EnterMultipleScope()) + { Assert.That(firstCommit.OwningProject, Is.EqualTo(Guid.Parse("000e9890-6935-43e6-a5d7-5d7cac601f4c"))); Assert.That(firstCommit.PreviousCommit, Is.EqualTo(Guid.Empty)); Assert.That(firstCommit.Description, Is.Null); @@ -182,16 +214,21 @@ public void Verify_that_particular_project_and_particular_commit_from_restapi_js } [Test] - public void Verify_that_particular_project_and_branches_from_restapi_json_can_be_deserialized() + [TestCase(false)] + [TestCase(true)] + public void Verify_that_particular_project_and_branches_from_restapi_json_can_be_deserialized(bool shouldDeserializeDerivedProperties) { var fileName = Path.Combine(TestContext.CurrentContext.WorkDirectory, "Data", "projects.000e9890-6935-43e6-a5d7-5d7cac601f4c.branches.json"); - using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) - { - var data = this.deSerializer.DeSerialize(stream, SerializationModeKind.JSON, SerializationTargetKind.PSM); + using var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read); - Assert.That(data.Count(), Is.EqualTo(1)); + var data = this.deSerializer.DeSerialize(stream, SerializationModeKind.JSON, SerializationTargetKind.PSM, shouldDeserializeDerivedProperties); - var branch = data.OfType().Single(x => x.Id == Guid.Parse("c294a463-6c9c-47a8-b592-01252c5ab2a7")); + Assert.That(data.Count(), Is.EqualTo(1)); + + var branch = data.OfType().Single(x => x.Id == Guid.Parse("c294a463-6c9c-47a8-b592-01252c5ab2a7")); + + using (Assert.EnterMultipleScope()) + { Assert.That(branch.OwningProject, Is.EqualTo(Guid.Parse("000e9890-6935-43e6-a5d7-5d7cac601f4c"))); Assert.That(branch.Name, Is.EqualTo("main")); Assert.That(branch.Description, Is.Null); diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AcceptActionUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AcceptActionUsageDeSerializer.cs index 762bdce0..8fc678fc 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AcceptActionUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AcceptActionUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class AcceptActionUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IAcceptActionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IAcceptActionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("AcceptActionUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IAcceptActionUsage DeSerialize(JsonElement jsonElement, Serializ } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.AcceptActionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actionDefinition"u8, out var actionDefinitionProperty)) { foreach (var arrayItem in actionDefinitionProperty.EnumerateArray()) @@ -2229,8 +2259,278 @@ internal static IAcceptActionUsage DeSerialize(JsonElement jsonElement, Serializ logger.LogDebug("the variantMembership Json property was not found in the AcceptActionUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.AcceptActionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 AcceptActionUsage: { 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 AcceptActionUsage: { 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 AcceptActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the AcceptActionUsage: { 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 AcceptActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the AcceptActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the AcceptActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the AcceptActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the AcceptActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the AcceptActionUsage: { 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 AcceptActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the AcceptActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the AcceptActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the AcceptActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the AcceptActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the AcceptActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the AcceptActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the AcceptActionUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the AcceptActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the AcceptActionUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ActionDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ActionDefinitionDeSerializer.cs index 1d2e7d0c..aebae081 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ActionDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ActionDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ActionDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IActionDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IActionDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ActionDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IActionDefinition DeSerialize(JsonElement jsonElement, Serializa } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.ActionDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("action"u8, out var actionProperty)) { foreach (var arrayItem in actionProperty.EnumerateArray()) @@ -1669,8 +1699,176 @@ internal static IActionDefinition DeSerialize(JsonElement jsonElement, Serializa logger.LogDebug("the variantMembership Json property was not found in the ActionDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.ActionDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ActionDefinition: { 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 ActionDefinition: { 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 ActionDefinition: { 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 ActionDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ActionDefinition: { 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 ActionDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the ActionDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ActionDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the ActionDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ActionDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ActionDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ActionUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ActionUsageDeSerializer.cs index 1f2c09d2..8eb7e48d 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ActionUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ActionUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ActionUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IActionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IActionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ActionUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IActionUsage DeSerialize(JsonElement jsonElement, SerializationM } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.ActionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actionDefinition"u8, out var actionDefinitionProperty)) { foreach (var arrayItem in actionDefinitionProperty.EnumerateArray()) @@ -2156,8 +2186,278 @@ internal static IActionUsage DeSerialize(JsonElement jsonElement, SerializationM logger.LogDebug("the variantMembership Json property was not found in the ActionUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.ActionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ActionUsage: { 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 ActionUsage: { 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 ActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the ActionUsage: { 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 ActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the ActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the ActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the ActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the ActionUsage: { 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 ActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the ActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the ActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the ActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the ActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the ActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ActionUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the ActionUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ActorMembershipDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ActorMembershipDeSerializer.cs index c385e48f..33d139d0 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ActorMembershipDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ActorMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ActorMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IActorMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IActorMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ActorMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IActorMembership DeSerialize(JsonElement jsonElement, Serializat } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.ActorMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -548,8 +578,193 @@ internal static IActorMembership DeSerialize(JsonElement jsonElement, Serializat logger.LogDebug("the visibility Json property was not found in the ActorMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.ActorMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ActorMembership: { 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 ActorMembership: { 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 ActorMembership: { 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 ActorMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the ActorMembership: { 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 ActorMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the ActorMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ActorMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the ActorMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ActorMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the ActorMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AllocationDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AllocationDefinitionDeSerializer.cs index b39600cc..77972b79 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AllocationDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AllocationDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class AllocationDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IAllocationDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IAllocationDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("AllocationDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IAllocationDefinition DeSerialize(JsonElement jsonElement, Seria } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Allocations.AllocationDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1769,8 +1799,232 @@ internal static IAllocationDefinition DeSerialize(JsonElement jsonElement, Seria logger.LogDebug("the variantMembership Json property was not found in the AllocationDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Allocations.AllocationDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 AllocationDefinition: { 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 AllocationDefinition: { 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 AllocationDefinition: { 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 AllocationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the AllocationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the AllocationDefinition: { 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 AllocationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the AllocationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the AllocationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the AllocationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the AllocationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the AllocationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the AllocationDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the AllocationDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AllocationUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AllocationUsageDeSerializer.cs index d019efd1..43764ce5 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AllocationUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AllocationUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class AllocationUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IAllocationUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IAllocationUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("AllocationUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IAllocationUsage DeSerialize(JsonElement jsonElement, Serializat } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Allocations.AllocationUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2360,8 +2390,334 @@ internal static IAllocationUsage DeSerialize(JsonElement jsonElement, Serializat logger.LogDebug("the variantMembership Json property was not found in the AllocationUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Allocations.AllocationUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 AllocationUsage: { 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 AllocationUsage: { 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 AllocationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the AllocationUsage: { 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 AllocationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the AllocationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the AllocationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the AllocationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the AllocationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the AllocationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the AllocationUsage: { 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 AllocationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the AllocationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the AllocationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the AllocationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the AllocationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the AllocationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the AllocationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the AllocationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the AllocationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the AllocationUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the AllocationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the AllocationUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AnalysisCaseDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AnalysisCaseDefinitionDeSerializer.cs index b7515a99..c8cc0a15 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AnalysisCaseDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AnalysisCaseDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class AnalysisCaseDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IAnalysisCaseDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IAnalysisCaseDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("AnalysisCaseDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IAnalysisCaseDefinition DeSerialize(JsonElement jsonElement, Ser } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.AnalysisCases.AnalysisCaseDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("action"u8, out var actionProperty)) { foreach (var arrayItem in actionProperty.EnumerateArray()) @@ -1839,8 +1869,176 @@ internal static IAnalysisCaseDefinition DeSerialize(JsonElement jsonElement, Ser logger.LogDebug("the variantMembership Json property was not found in the AnalysisCaseDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.AnalysisCases.AnalysisCaseDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 AnalysisCaseDefinition: { 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 AnalysisCaseDefinition: { 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 AnalysisCaseDefinition: { 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 AnalysisCaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the AnalysisCaseDefinition: { 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 AnalysisCaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the AnalysisCaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the AnalysisCaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the AnalysisCaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the AnalysisCaseDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the AnalysisCaseDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AnalysisCaseUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AnalysisCaseUsageDeSerializer.cs index df3ce09f..5928570f 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AnalysisCaseUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AnalysisCaseUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class AnalysisCaseUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IAnalysisCaseUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IAnalysisCaseUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("AnalysisCaseUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IAnalysisCaseUsage DeSerialize(JsonElement jsonElement, Serializ } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.AnalysisCases.AnalysisCaseUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actorParameter"u8, out var actorParameterProperty)) { foreach (var arrayItem in actorParameterProperty.EnumerateArray()) @@ -2290,8 +2320,278 @@ internal static IAnalysisCaseUsage DeSerialize(JsonElement jsonElement, Serializ logger.LogDebug("the variantMembership Json property was not found in the AnalysisCaseUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.AnalysisCases.AnalysisCaseUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 AnalysisCaseUsage: { 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 AnalysisCaseUsage: { 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 AnalysisCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the AnalysisCaseUsage: { 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 AnalysisCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the AnalysisCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the AnalysisCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the AnalysisCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the AnalysisCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the AnalysisCaseUsage: { 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 AnalysisCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the AnalysisCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the AnalysisCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the AnalysisCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the AnalysisCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the AnalysisCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the AnalysisCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the AnalysisCaseUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the AnalysisCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the AnalysisCaseUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AnnotatingElementDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AnnotatingElementDeSerializer.cs index 160f471c..4dbe3f02 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AnnotatingElementDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AnnotatingElementDeSerializer.cs @@ -49,13 +49,16 @@ internal static class AnnotatingElementDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IAnnotatingElement DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IAnnotatingElement DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("AnnotatingElementDeSerializer"); @@ -85,6 +88,33 @@ internal static IAnnotatingElement DeSerialize(JsonElement jsonElement, Serializ } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Root.Annotations.AnnotatingElement dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -465,8 +495,128 @@ internal static IAnnotatingElement DeSerialize(JsonElement jsonElement, Serializ logger.LogDebug("the textualRepresentation Json property was not found in the AnnotatingElement: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Root.Annotations.AnnotatingElement dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.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; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AnnotationDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AnnotationDeSerializer.cs index ad732032..7d80159c 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AnnotationDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AnnotationDeSerializer.cs @@ -49,13 +49,16 @@ internal static class AnnotationDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IAnnotation DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IAnnotation DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("AnnotationDeSerializer"); @@ -85,6 +88,33 @@ internal static IAnnotation DeSerialize(JsonElement jsonElement, SerializationMo } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Root.Annotations.Annotation dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -579,8 +609,209 @@ internal static IAnnotation DeSerialize(JsonElement jsonElement, SerializationMo logger.LogDebug("the textualRepresentation Json property was not found in the Annotation: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Root.Annotations.Annotation dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Annotation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("annotatedElement"u8, out var annotatedElementProperty)) + { + if (annotatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.AnnotatedElement = Guid.Empty; + logger.LogDebug($"the Annotation.AnnotatedElement property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (annotatedElementProperty.TryGetProperty("@id"u8, out var annotatedElementExternalIdProperty)) + { + var propertyValue = annotatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.AnnotatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the annotatedElement Json property was not found in the Annotation: { 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 Annotation: { 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 Annotation: { 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 Annotation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Annotation: { 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 Annotation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Annotation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Annotation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Annotation: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Annotation: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AssertConstraintUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AssertConstraintUsageDeSerializer.cs index bfc01ecb..3a773da0 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AssertConstraintUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AssertConstraintUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class AssertConstraintUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IAssertConstraintUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IAssertConstraintUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("AssertConstraintUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IAssertConstraintUsage DeSerialize(JsonElement jsonElement, Seri } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Constraints.AssertConstraintUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2254,8 +2284,290 @@ internal static IAssertConstraintUsage DeSerialize(JsonElement jsonElement, Seri logger.LogDebug("the variantMembership Json property was not found in the AssertConstraintUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Constraints.AssertConstraintUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 AssertConstraintUsage: { 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 AssertConstraintUsage: { 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 AssertConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the AssertConstraintUsage: { 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 AssertConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the AssertConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the AssertConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the AssertConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the AssertConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the AssertConstraintUsage: { 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 AssertConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the AssertConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isNegated"u8, out var isNegatedProperty)) + { + if (isNegatedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsNegated = isNegatedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isNegated Json property was not found in the AssertConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the AssertConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the AssertConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the AssertConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the AssertConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the AssertConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the AssertConstraintUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the AssertConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the AssertConstraintUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AssignmentActionUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AssignmentActionUsageDeSerializer.cs index 03b56d19..a70f09c0 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AssignmentActionUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AssignmentActionUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class AssignmentActionUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IAssignmentActionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IAssignmentActionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("AssignmentActionUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IAssignmentActionUsage DeSerialize(JsonElement jsonElement, Seri } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.AssignmentActionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actionDefinition"u8, out var actionDefinitionProperty)) { foreach (var arrayItem in actionDefinitionProperty.EnumerateArray()) @@ -2229,8 +2259,278 @@ internal static IAssignmentActionUsage DeSerialize(JsonElement jsonElement, Seri logger.LogDebug("the variantMembership Json property was not found in the AssignmentActionUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.AssignmentActionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 AssignmentActionUsage: { 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 AssignmentActionUsage: { 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 AssignmentActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the AssignmentActionUsage: { 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 AssignmentActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the AssignmentActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the AssignmentActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the AssignmentActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the AssignmentActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the AssignmentActionUsage: { 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 AssignmentActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the AssignmentActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the AssignmentActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the AssignmentActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the AssignmentActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the AssignmentActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the AssignmentActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the AssignmentActionUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the AssignmentActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the AssignmentActionUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AssociationDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AssociationDeSerializer.cs index b52440a7..e6bbca87 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AssociationDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AssociationDeSerializer.cs @@ -49,13 +49,16 @@ internal static class AssociationDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IAssociation DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IAssociation DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("AssociationDeSerializer"); @@ -85,6 +88,33 @@ internal static IAssociation DeSerialize(JsonElement jsonElement, SerializationM } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Associations.Association dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1105,8 +1135,208 @@ internal static IAssociation DeSerialize(JsonElement jsonElement, SerializationM logger.LogDebug("the unioningType Json property was not found in the Association: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Associations.Association dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Association: { 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 Association: { 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 Association: { 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 Association: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Association: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Association: { 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 Association: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Association: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Association: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Association: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Association: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Association: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AssociationStructureDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AssociationStructureDeSerializer.cs index 8e1c40c0..e5f0fc7f 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AssociationStructureDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AssociationStructureDeSerializer.cs @@ -49,13 +49,16 @@ internal static class AssociationStructureDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IAssociationStructure DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IAssociationStructure DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("AssociationStructureDeSerializer"); @@ -85,6 +88,33 @@ internal static IAssociationStructure DeSerialize(JsonElement jsonElement, Seria } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Associations.AssociationStructure dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1105,8 +1135,208 @@ internal static IAssociationStructure DeSerialize(JsonElement jsonElement, Seria logger.LogDebug("the unioningType Json property was not found in the AssociationStructure: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Associations.AssociationStructure dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 AssociationStructure: { 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 AssociationStructure: { 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 AssociationStructure: { 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 AssociationStructure: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the AssociationStructure: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the AssociationStructure: { 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 AssociationStructure: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the AssociationStructure: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the AssociationStructure: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the AssociationStructure: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the AssociationStructure: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the AssociationStructure: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AttributeDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AttributeDefinitionDeSerializer.cs index 2741aa2a..d6759ae4 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AttributeDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AttributeDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class AttributeDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IAttributeDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IAttributeDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("AttributeDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IAttributeDefinition DeSerialize(JsonElement jsonElement, Serial } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Attributes.AttributeDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1617,8 +1647,164 @@ internal static IAttributeDefinition DeSerialize(JsonElement jsonElement, Serial logger.LogDebug("the variantMembership Json property was not found in the AttributeDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Attributes.AttributeDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 AttributeDefinition: { 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 AttributeDefinition: { 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 AttributeDefinition: { 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 AttributeDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the AttributeDefinition: { 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 AttributeDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the AttributeDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the AttributeDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the AttributeDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the AttributeDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AttributeUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AttributeUsageDeSerializer.cs index 0e56bc6c..1df2b3e1 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AttributeUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/AttributeUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class AttributeUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IAttributeUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IAttributeUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("AttributeUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IAttributeUsage DeSerialize(JsonElement jsonElement, Serializati } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Attributes.AttributeUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2111,8 +2141,257 @@ internal static IAttributeUsage DeSerialize(JsonElement jsonElement, Serializati logger.LogDebug("the variantMembership Json property was not found in the AttributeUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Attributes.AttributeUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 AttributeUsage: { 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 AttributeUsage: { 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 AttributeUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the AttributeUsage: { 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 AttributeUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the AttributeUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the AttributeUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the AttributeUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the AttributeUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the AttributeUsage: { 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 AttributeUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the AttributeUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the AttributeUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the AttributeUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the AttributeUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the AttributeUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the AttributeUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the AttributeUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/BehaviorDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/BehaviorDeSerializer.cs index 5db87685..0e5bc243 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/BehaviorDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/BehaviorDeSerializer.cs @@ -49,13 +49,16 @@ internal static class BehaviorDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IBehavior DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IBehavior DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("BehaviorDeSerializer"); @@ -85,6 +88,33 @@ internal static IBehavior DeSerialize(JsonElement jsonElement, SerializationMode } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Behaviors.Behavior dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1005,8 +1035,152 @@ internal static IBehavior DeSerialize(JsonElement jsonElement, SerializationMode logger.LogDebug("the unioningType Json property was not found in the Behavior: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Behaviors.Behavior dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Behavior: { 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 Behavior: { 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 Behavior: { 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 Behavior: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Behavior: { 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 Behavior: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Behavior: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Behavior: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Behavior: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/BindingConnectorAsUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/BindingConnectorAsUsageDeSerializer.cs index 3811d985..e68e0091 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/BindingConnectorAsUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/BindingConnectorAsUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class BindingConnectorAsUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IBindingConnectorAsUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IBindingConnectorAsUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("BindingConnectorAsUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IBindingConnectorAsUsage DeSerialize(JsonElement jsonElement, Se } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Connections.BindingConnectorAsUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2275,8 +2305,313 @@ internal static IBindingConnectorAsUsage DeSerialize(JsonElement jsonElement, Se logger.LogDebug("the variantMembership Json property was not found in the BindingConnectorAsUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Connections.BindingConnectorAsUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 BindingConnectorAsUsage: { 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 BindingConnectorAsUsage: { 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 BindingConnectorAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the BindingConnectorAsUsage: { 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 BindingConnectorAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the BindingConnectorAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the BindingConnectorAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the BindingConnectorAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the BindingConnectorAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the BindingConnectorAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the BindingConnectorAsUsage: { 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 BindingConnectorAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the BindingConnectorAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the BindingConnectorAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the BindingConnectorAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the BindingConnectorAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the BindingConnectorAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the BindingConnectorAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the BindingConnectorAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the BindingConnectorAsUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the BindingConnectorAsUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/BindingConnectorDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/BindingConnectorDeSerializer.cs index a498bd3a..970b8c19 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/BindingConnectorDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/BindingConnectorDeSerializer.cs @@ -49,13 +49,16 @@ internal static class BindingConnectorDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IBindingConnector DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IBindingConnector DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("BindingConnectorDeSerializer"); @@ -85,6 +88,33 @@ internal static IBindingConnector DeSerialize(JsonElement jsonElement, Serializa } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Connectors.BindingConnector dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1563,8 +1593,313 @@ internal static IBindingConnector DeSerialize(JsonElement jsonElement, Serializa logger.LogDebug("the unioningType Json property was not found in the BindingConnector: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Connectors.BindingConnector dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 BindingConnector: { 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 BindingConnector: { 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 BindingConnector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the BindingConnector: { 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 BindingConnector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the BindingConnector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the BindingConnector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the BindingConnector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the BindingConnector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the BindingConnector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the BindingConnector: { 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 BindingConnector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the BindingConnector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the BindingConnector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the BindingConnector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the BindingConnector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the BindingConnector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the BindingConnector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the BindingConnector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the BindingConnector: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the BindingConnector: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/BooleanExpressionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/BooleanExpressionDeSerializer.cs index 1602d18c..64ef5199 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/BooleanExpressionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/BooleanExpressionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class BooleanExpressionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IBooleanExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IBooleanExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("BooleanExpressionDeSerializer"); @@ -85,6 +88,33 @@ internal static IBooleanExpression DeSerialize(JsonElement jsonElement, Serializ } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Functions.BooleanExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1480,8 +1510,257 @@ internal static IBooleanExpression DeSerialize(JsonElement jsonElement, Serializ logger.LogDebug("the unioningType Json property was not found in the BooleanExpression: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Functions.BooleanExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 BooleanExpression: { 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 BooleanExpression: { 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 BooleanExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the BooleanExpression: { 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 BooleanExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the BooleanExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the BooleanExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the BooleanExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the BooleanExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the BooleanExpression: { 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 BooleanExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the BooleanExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the BooleanExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the BooleanExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the BooleanExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the BooleanExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the BooleanExpression: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the BooleanExpression: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CalculationDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CalculationDefinitionDeSerializer.cs index dab0c3c6..0a9e531b 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CalculationDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CalculationDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class CalculationDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ICalculationDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ICalculationDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("CalculationDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static ICalculationDefinition DeSerialize(JsonElement jsonElement, Seri } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Calculations.CalculationDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("action"u8, out var actionProperty)) { foreach (var arrayItem in actionProperty.EnumerateArray()) @@ -1746,8 +1776,176 @@ internal static ICalculationDefinition DeSerialize(JsonElement jsonElement, Seri logger.LogDebug("the variantMembership Json property was not found in the CalculationDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Calculations.CalculationDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 CalculationDefinition: { 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 CalculationDefinition: { 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 CalculationDefinition: { 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 CalculationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the CalculationDefinition: { 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 CalculationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the CalculationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the CalculationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the CalculationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the CalculationDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the CalculationDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CalculationUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CalculationUsageDeSerializer.cs index 57ce28e3..c648facd 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CalculationUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CalculationUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class CalculationUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ICalculationUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ICalculationUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("CalculationUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static ICalculationUsage DeSerialize(JsonElement jsonElement, Serializa } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Calculations.CalculationUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2197,8 +2227,278 @@ internal static ICalculationUsage DeSerialize(JsonElement jsonElement, Serializa logger.LogDebug("the variantMembership Json property was not found in the CalculationUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Calculations.CalculationUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 CalculationUsage: { 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 CalculationUsage: { 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 CalculationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the CalculationUsage: { 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 CalculationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the CalculationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the CalculationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the CalculationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the CalculationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the CalculationUsage: { 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 CalculationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the CalculationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the CalculationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the CalculationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the CalculationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the CalculationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the CalculationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the CalculationUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the CalculationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the CalculationUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CaseDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CaseDefinitionDeSerializer.cs index 416380db..8623f2fc 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CaseDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CaseDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class CaseDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ICaseDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ICaseDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("CaseDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static ICaseDefinition DeSerialize(JsonElement jsonElement, Serializati } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Cases.CaseDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("action"u8, out var actionProperty)) { foreach (var arrayItem in actionProperty.EnumerateArray()) @@ -1815,8 +1845,176 @@ internal static ICaseDefinition DeSerialize(JsonElement jsonElement, Serializati logger.LogDebug("the variantMembership Json property was not found in the CaseDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Cases.CaseDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 CaseDefinition: { 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 CaseDefinition: { 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 CaseDefinition: { 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 CaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the CaseDefinition: { 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 CaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the CaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the CaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the CaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the CaseDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the CaseDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CaseUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CaseUsageDeSerializer.cs index 08487765..656d9f11 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CaseUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CaseUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class CaseUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ICaseUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ICaseUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("CaseUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static ICaseUsage DeSerialize(JsonElement jsonElement, SerializationMod } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Cases.CaseUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actorParameter"u8, out var actorParameterProperty)) { foreach (var arrayItem in actorParameterProperty.EnumerateArray()) @@ -2266,8 +2296,278 @@ internal static ICaseUsage DeSerialize(JsonElement jsonElement, SerializationMod logger.LogDebug("the variantMembership Json property was not found in the CaseUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Cases.CaseUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 CaseUsage: { 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 CaseUsage: { 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 CaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the CaseUsage: { 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 CaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the CaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the CaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the CaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the CaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the CaseUsage: { 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 CaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the CaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the CaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the CaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the CaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the CaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the CaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the CaseUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the CaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the CaseUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ClassDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ClassDeSerializer.cs index 33eb2f5b..035085f8 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ClassDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ClassDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ClassDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IClass DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IClass DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ClassDeSerializer"); @@ -85,6 +88,33 @@ internal static IClass DeSerialize(JsonElement jsonElement, SerializationModeKin } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Classes.Class dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -985,8 +1015,152 @@ internal static IClass DeSerialize(JsonElement jsonElement, SerializationModeKin logger.LogDebug("the unioningType Json property was not found in the Class: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Classes.Class dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Class: { 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 Class: { 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 Class: { 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 Class: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Class: { 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 Class: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Class: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Class: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Class: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ClassifierDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ClassifierDeSerializer.cs index 2149a0bd..1ea137c3 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ClassifierDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ClassifierDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ClassifierDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IClassifier DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IClassifier DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ClassifierDeSerializer"); @@ -85,6 +88,33 @@ internal static IClassifier DeSerialize(JsonElement jsonElement, SerializationMo } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Classifiers.Classifier dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -985,8 +1015,152 @@ internal static IClassifier DeSerialize(JsonElement jsonElement, SerializationMo logger.LogDebug("the unioningType Json property was not found in the Classifier: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Classifiers.Classifier dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Classifier: { 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 Classifier: { 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 Classifier: { 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 Classifier: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Classifier: { 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 Classifier: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Classifier: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Classifier: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Classifier: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CollectExpressionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CollectExpressionDeSerializer.cs index 47ae1d67..d7d7abaa 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CollectExpressionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CollectExpressionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class CollectExpressionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ICollectExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ICollectExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("CollectExpressionDeSerializer"); @@ -85,6 +88,33 @@ internal static ICollectExpression DeSerialize(JsonElement jsonElement, Serializ } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.CollectExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1539,8 +1569,271 @@ internal static ICollectExpression DeSerialize(JsonElement jsonElement, Serializ logger.LogDebug("the unioningType Json property was not found in the CollectExpression: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.CollectExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 CollectExpression: { 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 CollectExpression: { 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 CollectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the CollectExpression: { 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 CollectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the CollectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the CollectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the CollectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the CollectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the CollectExpression: { 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 CollectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the CollectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the CollectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the CollectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the CollectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the CollectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("operator"u8, out var operatorProperty)) + { + var propertyValue = operatorProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Operator = propertyValue; + } + } + else + { + logger.LogDebug("the operator Json property was not found in the CollectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the CollectExpression: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the CollectExpression: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CommentDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CommentDeSerializer.cs index 9dffd308..0d08550e 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CommentDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CommentDeSerializer.cs @@ -49,13 +49,16 @@ internal static class CommentDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IComment DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IComment DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("CommentDeSerializer"); @@ -85,6 +88,33 @@ internal static IComment DeSerialize(JsonElement jsonElement, SerializationModeK } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Root.Annotations.Comment dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -488,8 +518,151 @@ internal static IComment DeSerialize(JsonElement jsonElement, SerializationModeK logger.LogDebug("the textualRepresentation Json property was not found in the Comment: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Root.Annotations.Comment dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Comment: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("body"u8, out var bodyProperty)) + { + var propertyValue = bodyProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Body = propertyValue; + } + } + else + { + logger.LogDebug("the body Json property was not found in the Comment: { 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 Comment: { 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 Comment: { 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 Comment: { 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 Comment: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("locale"u8, out var localeProperty)) + { + dtoInstance.Locale = localeProperty.GetString(); + } + else + { + logger.LogDebug("the locale Json property was not found in the Comment: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Comment: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Comment: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConcernDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConcernDefinitionDeSerializer.cs index 2ee8ad75..4eb459df 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConcernDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConcernDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ConcernDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IConcernDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IConcernDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ConcernDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IConcernDefinition DeSerialize(JsonElement jsonElement, Serializ } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.ConcernDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actorParameter"u8, out var actorParameterProperty)) { foreach (var arrayItem in actorParameterProperty.EnumerateArray()) @@ -1848,8 +1878,176 @@ internal static IConcernDefinition DeSerialize(JsonElement jsonElement, Serializ logger.LogDebug("the variantMembership Json property was not found in the ConcernDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.ConcernDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ConcernDefinition: { 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 ConcernDefinition: { 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 ConcernDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ConcernDefinition: { 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 ConcernDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the ConcernDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ConcernDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the ConcernDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ConcernDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ConcernDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("reqId"u8, out var reqIdProperty)) + { + dtoInstance.ReqId = reqIdProperty.GetString(); + } + else + { + logger.LogDebug("the reqId Json property was not found in the ConcernDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConcernUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConcernUsageDeSerializer.cs index e8a9e3c5..42d81b72 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConcernUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConcernUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ConcernUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IConcernUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IConcernUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ConcernUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IConcernUsage DeSerialize(JsonElement jsonElement, Serialization } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.ConcernUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actorParameter"u8, out var actorParameterProperty)) { foreach (var arrayItem in actorParameterProperty.EnumerateArray()) @@ -2359,8 +2389,278 @@ internal static IConcernUsage DeSerialize(JsonElement jsonElement, Serialization logger.LogDebug("the variantMembership Json property was not found in the ConcernUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.ConcernUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ConcernUsage: { 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 ConcernUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the ConcernUsage: { 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 ConcernUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ConcernUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the ConcernUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the ConcernUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the ConcernUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the ConcernUsage: { 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 ConcernUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the ConcernUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the ConcernUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the ConcernUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ConcernUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the ConcernUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the ConcernUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ConcernUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ConcernUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the ConcernUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("reqId"u8, out var reqIdProperty)) + { + dtoInstance.ReqId = reqIdProperty.GetString(); + } + else + { + logger.LogDebug("the reqId Json property was not found in the ConcernUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConjugatedPortDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConjugatedPortDefinitionDeSerializer.cs index 7a3aa968..61f528cd 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConjugatedPortDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConjugatedPortDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ConjugatedPortDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IConjugatedPortDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IConjugatedPortDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ConjugatedPortDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IConjugatedPortDefinition DeSerialize(JsonElement jsonElement, S } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Ports.ConjugatedPortDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1655,8 +1685,176 @@ internal static IConjugatedPortDefinition DeSerialize(JsonElement jsonElement, S logger.LogDebug("the variantMembership Json property was not found in the ConjugatedPortDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Ports.ConjugatedPortDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ConjugatedPortDefinition: { 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 ConjugatedPortDefinition: { 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 ConjugatedPortDefinition: { 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 ConjugatedPortDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ConjugatedPortDefinition: { 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 ConjugatedPortDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the ConjugatedPortDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ConjugatedPortDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the ConjugatedPortDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ConjugatedPortDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ConjugatedPortDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConjugatedPortTypingDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConjugatedPortTypingDeSerializer.cs index 6ddcf4d6..921982fb 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConjugatedPortTypingDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConjugatedPortTypingDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ConjugatedPortTypingDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IConjugatedPortTyping DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IConjugatedPortTyping DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ConjugatedPortTypingDeSerializer"); @@ -85,6 +88,33 @@ internal static IConjugatedPortTyping DeSerialize(JsonElement jsonElement, Seria } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Ports.ConjugatedPortTyping dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -556,8 +586,234 @@ internal static IConjugatedPortTyping DeSerialize(JsonElement jsonElement, Seria logger.LogDebug("the typedFeature Json property was not found in the ConjugatedPortTyping: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Ports.ConjugatedPortTyping dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ConjugatedPortTyping: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("conjugatedPortDefinition"u8, out var conjugatedPortDefinitionProperty)) + { + if (conjugatedPortDefinitionProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.ConjugatedPortDefinition = Guid.Empty; + logger.LogDebug($"the ConjugatedPortTyping.ConjugatedPortDefinition property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (conjugatedPortDefinitionProperty.TryGetProperty("@id"u8, out var conjugatedPortDefinitionExternalIdProperty)) + { + var propertyValue = conjugatedPortDefinitionExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.ConjugatedPortDefinition = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the conjugatedPortDefinition Json property was not found in the ConjugatedPortTyping: { 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 ConjugatedPortTyping: { 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 ConjugatedPortTyping: { 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 ConjugatedPortTyping: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the ConjugatedPortTyping: { 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 ConjugatedPortTyping: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the ConjugatedPortTyping: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ConjugatedPortTyping: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the ConjugatedPortTyping: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ConjugatedPortTyping: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("typedFeature"u8, out var typedFeatureProperty)) + { + if (typedFeatureProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.TypedFeature = Guid.Empty; + logger.LogDebug($"the ConjugatedPortTyping.TypedFeature property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (typedFeatureProperty.TryGetProperty("@id"u8, out var typedFeatureExternalIdProperty)) + { + var propertyValue = typedFeatureExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.TypedFeature = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the typedFeature Json property was not found in the ConjugatedPortTyping: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConjugationDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConjugationDeSerializer.cs index 8c67f66e..9854a286 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConjugationDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConjugationDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ConjugationDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IConjugation DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IConjugation DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ConjugationDeSerializer"); @@ -85,6 +88,33 @@ internal static IConjugation DeSerialize(JsonElement jsonElement, SerializationM } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Types.Conjugation dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -531,8 +561,234 @@ internal static IConjugation DeSerialize(JsonElement jsonElement, SerializationM logger.LogDebug("the textualRepresentation Json property was not found in the Conjugation: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Types.Conjugation dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Conjugation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("conjugatedType"u8, out var conjugatedTypeProperty)) + { + if (conjugatedTypeProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.ConjugatedType = Guid.Empty; + logger.LogDebug($"the Conjugation.ConjugatedType property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (conjugatedTypeProperty.TryGetProperty("@id"u8, out var conjugatedTypeExternalIdProperty)) + { + var propertyValue = conjugatedTypeExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.ConjugatedType = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the conjugatedType Json property was not found in the Conjugation: { 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 Conjugation: { 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 Conjugation: { 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 Conjugation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Conjugation: { 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 Conjugation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("originalType"u8, out var originalTypeProperty)) + { + if (originalTypeProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OriginalType = Guid.Empty; + logger.LogDebug($"the Conjugation.OriginalType property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (originalTypeProperty.TryGetProperty("@id"u8, out var originalTypeExternalIdProperty)) + { + var propertyValue = originalTypeExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OriginalType = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the originalType Json property was not found in the Conjugation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Conjugation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Conjugation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Conjugation: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Conjugation: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConnectionDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConnectionDefinitionDeSerializer.cs index 81a9b347..63dfd15a 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConnectionDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConnectionDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ConnectionDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IConnectionDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IConnectionDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ConnectionDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IConnectionDefinition DeSerialize(JsonElement jsonElement, Seria } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Connections.ConnectionDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1749,8 +1779,232 @@ internal static IConnectionDefinition DeSerialize(JsonElement jsonElement, Seria logger.LogDebug("the variantMembership Json property was not found in the ConnectionDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Connections.ConnectionDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ConnectionDefinition: { 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 ConnectionDefinition: { 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 ConnectionDefinition: { 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 ConnectionDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ConnectionDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the ConnectionDefinition: { 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 ConnectionDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the ConnectionDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ConnectionDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the ConnectionDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the ConnectionDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ConnectionDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the ConnectionDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ConnectionDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConnectionUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConnectionUsageDeSerializer.cs index bc1601c8..3f5885ed 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConnectionUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConnectionUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ConnectionUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IConnectionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IConnectionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ConnectionUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IConnectionUsage DeSerialize(JsonElement jsonElement, Serializat } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Connections.ConnectionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2360,8 +2390,334 @@ internal static IConnectionUsage DeSerialize(JsonElement jsonElement, Serializat logger.LogDebug("the variantMembership Json property was not found in the ConnectionUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Connections.ConnectionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ConnectionUsage: { 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 ConnectionUsage: { 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 ConnectionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the ConnectionUsage: { 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 ConnectionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ConnectionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the ConnectionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the ConnectionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the ConnectionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the ConnectionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the ConnectionUsage: { 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 ConnectionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the ConnectionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the ConnectionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the ConnectionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ConnectionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the ConnectionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the ConnectionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the ConnectionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ConnectionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the ConnectionUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ConnectionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the ConnectionUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConnectorDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConnectorDeSerializer.cs index 9972c691..71f589ef 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConnectorDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConnectorDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ConnectorDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IConnector DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IConnector DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ConnectorDeSerializer"); @@ -85,6 +88,33 @@ internal static IConnector DeSerialize(JsonElement jsonElement, SerializationMod } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Connectors.Connector dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1563,8 +1593,313 @@ internal static IConnector DeSerialize(JsonElement jsonElement, SerializationMod logger.LogDebug("the unioningType Json property was not found in the Connector: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Connectors.Connector dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Connector: { 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 Connector: { 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 Connector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the Connector: { 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 Connector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Connector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the Connector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the Connector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the Connector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the Connector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Connector: { 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 Connector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the Connector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the Connector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Connector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the Connector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the Connector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Connector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Connector: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Connector: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Connector: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConstraintDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConstraintDefinitionDeSerializer.cs index f15cd625..40ba57c8 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConstraintDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConstraintDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ConstraintDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IConstraintDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IConstraintDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ConstraintDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IConstraintDefinition DeSerialize(JsonElement jsonElement, Seria } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Constraints.ConstraintDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1706,8 +1736,176 @@ internal static IConstraintDefinition DeSerialize(JsonElement jsonElement, Seria logger.LogDebug("the variantMembership Json property was not found in the ConstraintDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Constraints.ConstraintDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ConstraintDefinition: { 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 ConstraintDefinition: { 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 ConstraintDefinition: { 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 ConstraintDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ConstraintDefinition: { 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 ConstraintDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the ConstraintDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ConstraintDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the ConstraintDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ConstraintDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ConstraintDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConstraintUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConstraintUsageDeSerializer.cs index 139fe675..ddd74d5a 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConstraintUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConstraintUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ConstraintUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IConstraintUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IConstraintUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ConstraintUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IConstraintUsage DeSerialize(JsonElement jsonElement, Serializat } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Constraints.ConstraintUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2217,8 +2247,278 @@ internal static IConstraintUsage DeSerialize(JsonElement jsonElement, Serializat logger.LogDebug("the variantMembership Json property was not found in the ConstraintUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Constraints.ConstraintUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ConstraintUsage: { 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 ConstraintUsage: { 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 ConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the ConstraintUsage: { 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 ConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the ConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the ConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the ConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the ConstraintUsage: { 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 ConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the ConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the ConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the ConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the ConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the ConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ConstraintUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ConstraintUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the ConstraintUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConstructorExpressionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConstructorExpressionDeSerializer.cs index 5175885d..9ae02298 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConstructorExpressionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ConstructorExpressionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ConstructorExpressionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IConstructorExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IConstructorExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ConstructorExpressionDeSerializer"); @@ -85,6 +88,33 @@ internal static IConstructorExpression DeSerialize(JsonElement jsonElement, Seri } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.ConstructorExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1525,8 +1555,257 @@ internal static IConstructorExpression DeSerialize(JsonElement jsonElement, Seri logger.LogDebug("the unioningType Json property was not found in the ConstructorExpression: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.ConstructorExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ConstructorExpression: { 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 ConstructorExpression: { 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 ConstructorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the ConstructorExpression: { 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 ConstructorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ConstructorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the ConstructorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the ConstructorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the ConstructorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the ConstructorExpression: { 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 ConstructorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the ConstructorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the ConstructorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ConstructorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the ConstructorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the ConstructorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ConstructorExpression: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ConstructorExpression: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CrossSubsettingDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CrossSubsettingDeSerializer.cs index 31358403..573b130d 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CrossSubsettingDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/CrossSubsettingDeSerializer.cs @@ -49,13 +49,16 @@ internal static class CrossSubsettingDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ICrossSubsetting DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ICrossSubsetting DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("CrossSubsettingDeSerializer"); @@ -85,6 +88,33 @@ internal static ICrossSubsetting DeSerialize(JsonElement jsonElement, Serializat } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.CrossSubsetting dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -507,8 +537,209 @@ internal static ICrossSubsetting DeSerialize(JsonElement jsonElement, Serializat logger.LogDebug("the textualRepresentation Json property was not found in the CrossSubsetting: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.CrossSubsetting dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 CrossSubsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("crossedFeature"u8, out var crossedFeatureProperty)) + { + if (crossedFeatureProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.CrossedFeature = Guid.Empty; + logger.LogDebug($"the CrossSubsetting.CrossedFeature property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (crossedFeatureProperty.TryGetProperty("@id"u8, out var crossedFeatureExternalIdProperty)) + { + var propertyValue = crossedFeatureExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.CrossedFeature = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the crossedFeature Json property was not found in the CrossSubsetting: { 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 CrossSubsetting: { 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 CrossSubsetting: { 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 CrossSubsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the CrossSubsetting: { 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 CrossSubsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the CrossSubsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the CrossSubsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the CrossSubsetting: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the CrossSubsetting: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DataTypeDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DataTypeDeSerializer.cs index dcd02167..923d9f04 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DataTypeDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DataTypeDeSerializer.cs @@ -49,13 +49,16 @@ internal static class DataTypeDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IDataType DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IDataType DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("DataTypeDeSerializer"); @@ -85,6 +88,33 @@ internal static IDataType DeSerialize(JsonElement jsonElement, SerializationMode } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.DataTypes.DataType dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -985,8 +1015,152 @@ internal static IDataType DeSerialize(JsonElement jsonElement, SerializationMode logger.LogDebug("the unioningType Json property was not found in the DataType: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.DataTypes.DataType dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 DataType: { 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 DataType: { 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 DataType: { 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 DataType: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the DataType: { 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 DataType: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the DataType: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the DataType: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the DataType: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DeSerializationProvider.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DeSerializationProvider.cs index bd0fe197..63b63347 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DeSerializationProvider.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DeSerializationProvider.cs @@ -41,7 +41,7 @@ internal static class DeSerializationProvider /// /// a dictionary that provides delegates for deserialization /// - private static readonly Dictionary> DeSerializerActionMap = new Dictionary> + private static readonly Dictionary> DeSerializerActionMap = new Dictionary> { { "AcceptActionUsage", AcceptActionUsageDeSerializer.DeSerialize }, { "ActionDefinition", ActionDefinitionDeSerializer.DeSerialize }, @@ -213,19 +213,19 @@ internal static class DeSerializationProvider }; /// - /// Provides the delegate for the + /// Provides the delegate for the /// that is to be deserialized /// /// /// The name of the subject that is to be serialized /// /// - /// A Delegate of + /// A Delegate of /// /// /// Thrown when the is not supported. /// - internal static Func Provide(string typeName) + internal static Func Provide(string typeName) { if (!DeSerializerActionMap.TryGetValue(typeName, out var func)) { diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DecisionNodeDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DecisionNodeDeSerializer.cs index 7c0ce12d..49d0d957 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DecisionNodeDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DecisionNodeDeSerializer.cs @@ -49,13 +49,16 @@ internal static class DecisionNodeDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IDecisionNode DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IDecisionNode DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("DecisionNodeDeSerializer"); @@ -85,6 +88,33 @@ internal static IDecisionNode DeSerialize(JsonElement jsonElement, Serialization } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.DecisionNode dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actionDefinition"u8, out var actionDefinitionProperty)) { foreach (var arrayItem in actionDefinitionProperty.EnumerateArray()) @@ -2156,8 +2186,278 @@ internal static IDecisionNode DeSerialize(JsonElement jsonElement, Serialization logger.LogDebug("the variantMembership Json property was not found in the DecisionNode: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.DecisionNode dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 DecisionNode: { 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 DecisionNode: { 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 DecisionNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the DecisionNode: { 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 DecisionNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the DecisionNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the DecisionNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the DecisionNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the DecisionNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the DecisionNode: { 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 DecisionNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the DecisionNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the DecisionNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the DecisionNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the DecisionNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the DecisionNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the DecisionNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the DecisionNode: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the DecisionNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the DecisionNode: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DefinitionDeSerializer.cs index f9a78571..42af26fa 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class DefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("DefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IDefinition DeSerialize(JsonElement jsonElement, SerializationMo } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.DefinitionAndUsage.Definition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1617,8 +1647,164 @@ internal static IDefinition DeSerialize(JsonElement jsonElement, SerializationMo logger.LogDebug("the variantMembership Json property was not found in the Definition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.DefinitionAndUsage.Definition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Definition: { 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 Definition: { 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 Definition: { 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 Definition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Definition: { 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 Definition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Definition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the Definition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Definition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Definition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DependencyDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DependencyDeSerializer.cs index 2b067afa..da50fd0f 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DependencyDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DependencyDeSerializer.cs @@ -49,13 +49,16 @@ internal static class DependencyDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IDependency DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IDependency DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("DependencyDeSerializer"); @@ -85,6 +88,33 @@ internal static IDependency DeSerialize(JsonElement jsonElement, SerializationMo } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Root.Dependencies.Dependency dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -497,8 +527,224 @@ internal static IDependency DeSerialize(JsonElement jsonElement, SerializationMo logger.LogDebug("the textualRepresentation Json property was not found in the Dependency: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Root.Dependencies.Dependency dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Dependency: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("client"u8, out var clientProperty)) + { + foreach (var arrayItem in clientProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var clientExternalIdProperty)) + { + var propertyValue = clientExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Client.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the client Json property was not found in the Dependency: { 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 Dependency: { 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 Dependency: { 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 Dependency: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Dependency: { 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 Dependency: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Dependency: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Dependency: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Dependency: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Dependency: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("supplier"u8, out var supplierProperty)) + { + foreach (var arrayItem in supplierProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var supplierExternalIdProperty)) + { + var propertyValue = supplierExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Supplier.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the supplier Json property was not found in the Dependency: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DifferencingDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DifferencingDeSerializer.cs index a68ae10b..a72bdc0d 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DifferencingDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DifferencingDeSerializer.cs @@ -49,13 +49,16 @@ internal static class DifferencingDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IDifferencing DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IDifferencing DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("DifferencingDeSerializer"); @@ -85,6 +88,33 @@ internal static IDifferencing DeSerialize(JsonElement jsonElement, Serialization } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Types.Differencing dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -507,8 +537,209 @@ internal static IDifferencing DeSerialize(JsonElement jsonElement, Serialization logger.LogDebug("the typeDifferenced Json property was not found in the Differencing: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Types.Differencing dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Differencing: { 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 Differencing: { 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 Differencing: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("differencingType"u8, out var differencingTypeProperty)) + { + if (differencingTypeProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.DifferencingType = Guid.Empty; + logger.LogDebug($"the Differencing.DifferencingType property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (differencingTypeProperty.TryGetProperty("@id"u8, out var differencingTypeExternalIdProperty)) + { + var propertyValue = differencingTypeExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.DifferencingType = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the differencingType Json property was not found in the Differencing: { 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 Differencing: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Differencing: { 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 Differencing: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Differencing: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Differencing: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Differencing: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Differencing: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DisjoiningDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DisjoiningDeSerializer.cs index 52ac9195..247e124b 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DisjoiningDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DisjoiningDeSerializer.cs @@ -49,13 +49,16 @@ internal static class DisjoiningDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IDisjoining DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IDisjoining DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("DisjoiningDeSerializer"); @@ -85,6 +88,33 @@ internal static IDisjoining DeSerialize(JsonElement jsonElement, SerializationMo } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Types.Disjoining dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -531,8 +561,234 @@ internal static IDisjoining DeSerialize(JsonElement jsonElement, SerializationMo logger.LogDebug("the typeDisjoined Json property was not found in the Disjoining: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Types.Disjoining dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Disjoining: { 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 Disjoining: { 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 Disjoining: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("disjoiningType"u8, out var disjoiningTypeProperty)) + { + if (disjoiningTypeProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.DisjoiningType = Guid.Empty; + logger.LogDebug($"the Disjoining.DisjoiningType property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (disjoiningTypeProperty.TryGetProperty("@id"u8, out var disjoiningTypeExternalIdProperty)) + { + var propertyValue = disjoiningTypeExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.DisjoiningType = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the disjoiningType Json property was not found in the Disjoining: { 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 Disjoining: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Disjoining: { 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 Disjoining: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Disjoining: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Disjoining: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Disjoining: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Disjoining: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("typeDisjoined"u8, out var typeDisjoinedProperty)) + { + if (typeDisjoinedProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.TypeDisjoined = Guid.Empty; + logger.LogDebug($"the Disjoining.TypeDisjoined property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (typeDisjoinedProperty.TryGetProperty("@id"u8, out var typeDisjoinedExternalIdProperty)) + { + var propertyValue = typeDisjoinedExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.TypeDisjoined = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the typeDisjoined Json property was not found in the Disjoining: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DocumentationDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DocumentationDeSerializer.cs index ef2474fb..747be30f 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DocumentationDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/DocumentationDeSerializer.cs @@ -49,13 +49,16 @@ internal static class DocumentationDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IDocumentation DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IDocumentation DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("DocumentationDeSerializer"); @@ -85,6 +88,33 @@ internal static IDocumentation DeSerialize(JsonElement jsonElement, Serializatio } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Root.Annotations.Documentation dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -493,8 +523,151 @@ internal static IDocumentation DeSerialize(JsonElement jsonElement, Serializatio logger.LogDebug("the textualRepresentation Json property was not found in the Documentation: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Root.Annotations.Documentation dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Documentation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("body"u8, out var bodyProperty)) + { + var propertyValue = bodyProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Body = propertyValue; + } + } + else + { + logger.LogDebug("the body Json property was not found in the Documentation: { 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 Documentation: { 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 Documentation: { 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 Documentation: { 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 Documentation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("locale"u8, out var localeProperty)) + { + dtoInstance.Locale = localeProperty.GetString(); + } + else + { + logger.LogDebug("the locale Json property was not found in the Documentation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Documentation: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Documentation: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ElementFilterMembershipDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ElementFilterMembershipDeSerializer.cs index 03238716..2b7f3b37 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ElementFilterMembershipDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ElementFilterMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ElementFilterMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IElementFilterMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IElementFilterMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ElementFilterMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IElementFilterMembership DeSerialize(JsonElement jsonElement, Se } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Packages.ElementFilterMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -548,8 +578,193 @@ internal static IElementFilterMembership DeSerialize(JsonElement jsonElement, Se logger.LogDebug("the visibility Json property was not found in the ElementFilterMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Packages.ElementFilterMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ElementFilterMembership: { 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 ElementFilterMembership: { 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 ElementFilterMembership: { 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 ElementFilterMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the ElementFilterMembership: { 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 ElementFilterMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the ElementFilterMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ElementFilterMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the ElementFilterMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ElementFilterMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the ElementFilterMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/EndFeatureMembershipDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/EndFeatureMembershipDeSerializer.cs index 253686a4..ea8ab8d4 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/EndFeatureMembershipDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/EndFeatureMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class EndFeatureMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IEndFeatureMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IEndFeatureMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("EndFeatureMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IEndFeatureMembership DeSerialize(JsonElement jsonElement, Seria } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.EndFeatureMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -548,8 +578,193 @@ internal static IEndFeatureMembership DeSerialize(JsonElement jsonElement, Seria logger.LogDebug("the visibility Json property was not found in the EndFeatureMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.EndFeatureMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 EndFeatureMembership: { 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 EndFeatureMembership: { 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 EndFeatureMembership: { 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 EndFeatureMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the EndFeatureMembership: { 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 EndFeatureMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the EndFeatureMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the EndFeatureMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the EndFeatureMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the EndFeatureMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the EndFeatureMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/EnumerationDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/EnumerationDefinitionDeSerializer.cs index 5f6b5ecd..c875f6e5 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/EnumerationDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/EnumerationDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class EnumerationDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IEnumerationDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IEnumerationDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("EnumerationDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IEnumerationDefinition DeSerialize(JsonElement jsonElement, Seri } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Enumerations.EnumerationDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1617,8 +1647,164 @@ internal static IEnumerationDefinition DeSerialize(JsonElement jsonElement, Seri logger.LogDebug("the variantMembership Json property was not found in the EnumerationDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Enumerations.EnumerationDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 EnumerationDefinition: { 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 EnumerationDefinition: { 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 EnumerationDefinition: { 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 EnumerationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the EnumerationDefinition: { 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 EnumerationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the EnumerationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the EnumerationDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the EnumerationDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the EnumerationDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/EnumerationUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/EnumerationUsageDeSerializer.cs index 5ab6f0b1..33f3c7ef 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/EnumerationUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/EnumerationUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class EnumerationUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IEnumerationUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IEnumerationUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("EnumerationUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IEnumerationUsage DeSerialize(JsonElement jsonElement, Serializa } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Enumerations.EnumerationUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2116,8 +2146,257 @@ internal static IEnumerationUsage DeSerialize(JsonElement jsonElement, Serializa logger.LogDebug("the variantMembership Json property was not found in the EnumerationUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Enumerations.EnumerationUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 EnumerationUsage: { 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 EnumerationUsage: { 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 EnumerationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the EnumerationUsage: { 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 EnumerationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the EnumerationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the EnumerationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the EnumerationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the EnumerationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the EnumerationUsage: { 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 EnumerationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the EnumerationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the EnumerationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the EnumerationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the EnumerationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the EnumerationUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the EnumerationUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the EnumerationUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/EventOccurrenceUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/EventOccurrenceUsageDeSerializer.cs index 1423c109..92d7a0b6 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/EventOccurrenceUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/EventOccurrenceUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class EventOccurrenceUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IEventOccurrenceUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IEventOccurrenceUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("EventOccurrenceUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IEventOccurrenceUsage DeSerialize(JsonElement jsonElement, Seria } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Occurrences.EventOccurrenceUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2181,8 +2211,278 @@ internal static IEventOccurrenceUsage DeSerialize(JsonElement jsonElement, Seria logger.LogDebug("the variantMembership Json property was not found in the EventOccurrenceUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Occurrences.EventOccurrenceUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 EventOccurrenceUsage: { 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 EventOccurrenceUsage: { 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 EventOccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the EventOccurrenceUsage: { 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 EventOccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the EventOccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the EventOccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the EventOccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the EventOccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the EventOccurrenceUsage: { 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 EventOccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the EventOccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the EventOccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the EventOccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the EventOccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the EventOccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the EventOccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the EventOccurrenceUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the EventOccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the EventOccurrenceUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ExhibitStateUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ExhibitStateUsageDeSerializer.cs index 80e06e7d..04a89b97 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ExhibitStateUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ExhibitStateUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ExhibitStateUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IExhibitStateUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IExhibitStateUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ExhibitStateUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IExhibitStateUsage DeSerialize(JsonElement jsonElement, Serializ } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.States.ExhibitStateUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2265,8 +2295,290 @@ internal static IExhibitStateUsage DeSerialize(JsonElement jsonElement, Serializ logger.LogDebug("the variantMembership Json property was not found in the ExhibitStateUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.States.ExhibitStateUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ExhibitStateUsage: { 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 ExhibitStateUsage: { 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 ExhibitStateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the ExhibitStateUsage: { 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 ExhibitStateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ExhibitStateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the ExhibitStateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the ExhibitStateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the ExhibitStateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the ExhibitStateUsage: { 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 ExhibitStateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the ExhibitStateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the ExhibitStateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isParallel"u8, out var isParallelProperty)) + { + if (isParallelProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsParallel = isParallelProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isParallel Json property was not found in the ExhibitStateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the ExhibitStateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ExhibitStateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the ExhibitStateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the ExhibitStateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ExhibitStateUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ExhibitStateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the ExhibitStateUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ExpressionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ExpressionDeSerializer.cs index 36c568c9..f0246ec1 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ExpressionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ExpressionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ExpressionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ExpressionDeSerializer"); @@ -85,6 +88,33 @@ internal static IExpression DeSerialize(JsonElement jsonElement, SerializationMo } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Functions.Expression dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1480,8 +1510,257 @@ internal static IExpression DeSerialize(JsonElement jsonElement, SerializationMo logger.LogDebug("the unioningType Json property was not found in the Expression: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Functions.Expression dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Expression: { 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 Expression: { 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 Expression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the Expression: { 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 Expression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Expression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the Expression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the Expression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the Expression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the Expression: { 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 Expression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the Expression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the Expression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Expression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the Expression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the Expression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Expression: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Expression: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureChainExpressionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureChainExpressionDeSerializer.cs index 649acd65..917fb7a6 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureChainExpressionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureChainExpressionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class FeatureChainExpressionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IFeatureChainExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IFeatureChainExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("FeatureChainExpressionDeSerializer"); @@ -85,6 +88,33 @@ internal static IFeatureChainExpression DeSerialize(JsonElement jsonElement, Ser } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.FeatureChainExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1564,8 +1594,271 @@ internal static IFeatureChainExpression DeSerialize(JsonElement jsonElement, Ser logger.LogDebug("the unioningType Json property was not found in the FeatureChainExpression: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.FeatureChainExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 FeatureChainExpression: { 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 FeatureChainExpression: { 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 FeatureChainExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the FeatureChainExpression: { 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 FeatureChainExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the FeatureChainExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the FeatureChainExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the FeatureChainExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the FeatureChainExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the FeatureChainExpression: { 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 FeatureChainExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the FeatureChainExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the FeatureChainExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the FeatureChainExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the FeatureChainExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the FeatureChainExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("operator"u8, out var operatorProperty)) + { + var propertyValue = operatorProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Operator = propertyValue; + } + } + else + { + logger.LogDebug("the operator Json property was not found in the FeatureChainExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the FeatureChainExpression: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the FeatureChainExpression: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureChainingDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureChainingDeSerializer.cs index aaf37104..a39ffda9 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureChainingDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureChainingDeSerializer.cs @@ -49,13 +49,16 @@ internal static class FeatureChainingDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IFeatureChaining DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IFeatureChaining DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("FeatureChainingDeSerializer"); @@ -85,6 +88,33 @@ internal static IFeatureChaining DeSerialize(JsonElement jsonElement, Serializat } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.FeatureChaining dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -507,8 +537,209 @@ internal static IFeatureChaining DeSerialize(JsonElement jsonElement, Serializat logger.LogDebug("the textualRepresentation Json property was not found in the FeatureChaining: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.FeatureChaining dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 FeatureChaining: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("chainingFeature"u8, out var chainingFeatureProperty)) + { + if (chainingFeatureProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.ChainingFeature = Guid.Empty; + logger.LogDebug($"the FeatureChaining.ChainingFeature property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (chainingFeatureProperty.TryGetProperty("@id"u8, out var chainingFeatureExternalIdProperty)) + { + var propertyValue = chainingFeatureExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.ChainingFeature = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the chainingFeature Json property was not found in the FeatureChaining: { 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 FeatureChaining: { 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 FeatureChaining: { 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 FeatureChaining: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the FeatureChaining: { 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 FeatureChaining: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the FeatureChaining: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the FeatureChaining: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the FeatureChaining: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the FeatureChaining: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureDeSerializer.cs index 1e2093bf..06a5b48c 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureDeSerializer.cs @@ -49,13 +49,16 @@ internal static class FeatureDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IFeature DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IFeature DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("FeatureDeSerializer"); @@ -85,6 +88,33 @@ internal static IFeature DeSerialize(JsonElement jsonElement, SerializationModeK } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.Feature dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1419,8 +1449,257 @@ internal static IFeature DeSerialize(JsonElement jsonElement, SerializationModeK logger.LogDebug("the unioningType Json property was not found in the Feature: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.Feature dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Feature: { 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 Feature: { 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 Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the Feature: { 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 Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the Feature: { 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 Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the Feature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Feature: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Feature: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureInvertingDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureInvertingDeSerializer.cs index a429798b..3cdf518b 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureInvertingDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureInvertingDeSerializer.cs @@ -49,13 +49,16 @@ internal static class FeatureInvertingDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IFeatureInverting DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IFeatureInverting DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("FeatureInvertingDeSerializer"); @@ -85,6 +88,33 @@ internal static IFeatureInverting DeSerialize(JsonElement jsonElement, Serializa } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.FeatureInverting dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -531,8 +561,234 @@ internal static IFeatureInverting DeSerialize(JsonElement jsonElement, Serializa logger.LogDebug("the textualRepresentation Json property was not found in the FeatureInverting: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.FeatureInverting dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 FeatureInverting: { 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 FeatureInverting: { 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 FeatureInverting: { 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 FeatureInverting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("featureInverted"u8, out var featureInvertedProperty)) + { + if (featureInvertedProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.FeatureInverted = Guid.Empty; + logger.LogDebug($"the FeatureInverting.FeatureInverted property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (featureInvertedProperty.TryGetProperty("@id"u8, out var featureInvertedExternalIdProperty)) + { + var propertyValue = featureInvertedExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.FeatureInverted = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the featureInverted Json property was not found in the FeatureInverting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("invertingFeature"u8, out var invertingFeatureProperty)) + { + if (invertingFeatureProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.InvertingFeature = Guid.Empty; + logger.LogDebug($"the FeatureInverting.InvertingFeature property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (invertingFeatureProperty.TryGetProperty("@id"u8, out var invertingFeatureExternalIdProperty)) + { + var propertyValue = invertingFeatureExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.InvertingFeature = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the invertingFeature Json property was not found in the FeatureInverting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the FeatureInverting: { 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 FeatureInverting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the FeatureInverting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the FeatureInverting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the FeatureInverting: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the FeatureInverting: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureMembershipDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureMembershipDeSerializer.cs index de7b5275..9d049801 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureMembershipDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class FeatureMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IFeatureMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IFeatureMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("FeatureMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IFeatureMembership DeSerialize(JsonElement jsonElement, Serializ } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Types.FeatureMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -548,8 +578,193 @@ internal static IFeatureMembership DeSerialize(JsonElement jsonElement, Serializ logger.LogDebug("the visibility Json property was not found in the FeatureMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Types.FeatureMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 FeatureMembership: { 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 FeatureMembership: { 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 FeatureMembership: { 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 FeatureMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the FeatureMembership: { 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 FeatureMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the FeatureMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the FeatureMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the FeatureMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the FeatureMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the FeatureMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureReferenceExpressionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureReferenceExpressionDeSerializer.cs index 168524fe..6ab38cf6 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureReferenceExpressionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureReferenceExpressionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class FeatureReferenceExpressionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IFeatureReferenceExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IFeatureReferenceExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("FeatureReferenceExpressionDeSerializer"); @@ -85,6 +88,33 @@ internal static IFeatureReferenceExpression DeSerialize(JsonElement jsonElement, } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.FeatureReferenceExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1505,8 +1535,257 @@ internal static IFeatureReferenceExpression DeSerialize(JsonElement jsonElement, logger.LogDebug("the unioningType Json property was not found in the FeatureReferenceExpression: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.FeatureReferenceExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 FeatureReferenceExpression: { 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 FeatureReferenceExpression: { 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 FeatureReferenceExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the FeatureReferenceExpression: { 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 FeatureReferenceExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the FeatureReferenceExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the FeatureReferenceExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the FeatureReferenceExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the FeatureReferenceExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the FeatureReferenceExpression: { 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 FeatureReferenceExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the FeatureReferenceExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the FeatureReferenceExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the FeatureReferenceExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the FeatureReferenceExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the FeatureReferenceExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the FeatureReferenceExpression: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the FeatureReferenceExpression: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureTypingDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureTypingDeSerializer.cs index 9b59656a..8ead0ad7 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureTypingDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureTypingDeSerializer.cs @@ -49,13 +49,16 @@ internal static class FeatureTypingDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IFeatureTyping DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IFeatureTyping DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("FeatureTypingDeSerializer"); @@ -85,6 +88,33 @@ internal static IFeatureTyping DeSerialize(JsonElement jsonElement, Serializatio } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.FeatureTyping dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -531,8 +561,234 @@ internal static IFeatureTyping DeSerialize(JsonElement jsonElement, Serializatio logger.LogDebug("the typedFeature Json property was not found in the FeatureTyping: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.FeatureTyping dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 FeatureTyping: { 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 FeatureTyping: { 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 FeatureTyping: { 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 FeatureTyping: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the FeatureTyping: { 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 FeatureTyping: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the FeatureTyping: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the FeatureTyping: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the FeatureTyping: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the FeatureTyping: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("type"u8, out var typeProperty)) + { + if (typeProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.Type = Guid.Empty; + logger.LogDebug($"the FeatureTyping.Type property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (typeProperty.TryGetProperty("@id"u8, out var typeExternalIdProperty)) + { + var propertyValue = typeExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Type = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the type Json property was not found in the FeatureTyping: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("typedFeature"u8, out var typedFeatureProperty)) + { + if (typedFeatureProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.TypedFeature = Guid.Empty; + logger.LogDebug($"the FeatureTyping.TypedFeature property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (typedFeatureProperty.TryGetProperty("@id"u8, out var typedFeatureExternalIdProperty)) + { + var propertyValue = typedFeatureExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.TypedFeature = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the typedFeature Json property was not found in the FeatureTyping: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureValueDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureValueDeSerializer.cs index eaf01ab5..1dc36b01 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureValueDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FeatureValueDeSerializer.cs @@ -49,13 +49,16 @@ internal static class FeatureValueDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IFeatureValue DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IFeatureValue DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("FeatureValueDeSerializer"); @@ -85,6 +88,33 @@ internal static IFeatureValue DeSerialize(JsonElement jsonElement, Serialization } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.FeatureValues.FeatureValue dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -597,8 +627,217 @@ internal static IFeatureValue DeSerialize(JsonElement jsonElement, Serialization logger.LogDebug("the visibility Json property was not found in the FeatureValue: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.FeatureValues.FeatureValue dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 FeatureValue: { 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 FeatureValue: { 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 FeatureValue: { 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 FeatureValue: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDefault"u8, out var isDefaultProperty)) + { + if (isDefaultProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDefault = isDefaultProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDefault Json property was not found in the FeatureValue: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the FeatureValue: { 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 FeatureValue: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isInitial"u8, out var isInitialProperty)) + { + if (isInitialProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsInitial = isInitialProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isInitial Json property was not found in the FeatureValue: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the FeatureValue: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the FeatureValue: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the FeatureValue: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the FeatureValue: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the FeatureValue: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FlowDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FlowDeSerializer.cs index 18274448..4e3d0852 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FlowDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FlowDeSerializer.cs @@ -49,13 +49,16 @@ internal static class FlowDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IFlow DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IFlow DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("FlowDeSerializer"); @@ -85,6 +88,33 @@ internal static IFlow DeSerialize(JsonElement jsonElement, SerializationModeKind } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Interactions.Flow dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1675,8 +1705,313 @@ internal static IFlow DeSerialize(JsonElement jsonElement, SerializationModeKind logger.LogDebug("the unioningType Json property was not found in the Flow: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Interactions.Flow dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Flow: { 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 Flow: { 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 Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the Flow: { 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 Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Flow: { 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 Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Flow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Flow: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Flow: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FlowDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FlowDefinitionDeSerializer.cs index ea2a84f9..2c359dab 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FlowDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FlowDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class FlowDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IFlowDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IFlowDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("FlowDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IFlowDefinition DeSerialize(JsonElement jsonElement, Serializati } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Flows.FlowDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("action"u8, out var actionProperty)) { foreach (var arrayItem in actionProperty.EnumerateArray()) @@ -1789,8 +1819,232 @@ internal static IFlowDefinition DeSerialize(JsonElement jsonElement, Serializati logger.LogDebug("the variantMembership Json property was not found in the FlowDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Flows.FlowDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 FlowDefinition: { 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 FlowDefinition: { 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 FlowDefinition: { 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 FlowDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the FlowDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the FlowDefinition: { 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 FlowDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the FlowDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the FlowDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the FlowDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the FlowDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the FlowDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the FlowDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the FlowDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FlowEndDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FlowEndDeSerializer.cs index f3ba77d4..5932d8a5 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FlowEndDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FlowEndDeSerializer.cs @@ -49,13 +49,16 @@ internal static class FlowEndDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IFlowEnd DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IFlowEnd DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("FlowEndDeSerializer"); @@ -85,6 +88,33 @@ internal static IFlowEnd DeSerialize(JsonElement jsonElement, SerializationModeK } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Interactions.FlowEnd dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1419,8 +1449,257 @@ internal static IFlowEnd DeSerialize(JsonElement jsonElement, SerializationModeK logger.LogDebug("the unioningType Json property was not found in the FlowEnd: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Interactions.FlowEnd dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 FlowEnd: { 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 FlowEnd: { 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 FlowEnd: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the FlowEnd: { 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 FlowEnd: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the FlowEnd: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the FlowEnd: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the FlowEnd: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the FlowEnd: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the FlowEnd: { 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 FlowEnd: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the FlowEnd: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the FlowEnd: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the FlowEnd: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the FlowEnd: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the FlowEnd: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the FlowEnd: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the FlowEnd: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FlowUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FlowUsageDeSerializer.cs index df6aa098..8ab3e1d3 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FlowUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FlowUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class FlowUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IFlowUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IFlowUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("FlowUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IFlowUsage DeSerialize(JsonElement jsonElement, SerializationMod } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Flows.FlowUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2412,8 +2442,334 @@ internal static IFlowUsage DeSerialize(JsonElement jsonElement, SerializationMod logger.LogDebug("the variantMembership Json property was not found in the FlowUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Flows.FlowUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 FlowUsage: { 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 FlowUsage: { 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 FlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the FlowUsage: { 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 FlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the FlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the FlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the FlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the FlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the FlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the FlowUsage: { 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 FlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the FlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the FlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the FlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the FlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the FlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the FlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the FlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the FlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the FlowUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the FlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the FlowUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ForLoopActionUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ForLoopActionUsageDeSerializer.cs index 45c80aa8..caa351b3 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ForLoopActionUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ForLoopActionUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ForLoopActionUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IForLoopActionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IForLoopActionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ForLoopActionUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IForLoopActionUsage DeSerialize(JsonElement jsonElement, Seriali } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.ForLoopActionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actionDefinition"u8, out var actionDefinitionProperty)) { foreach (var arrayItem in actionDefinitionProperty.EnumerateArray()) @@ -2231,8 +2261,278 @@ internal static IForLoopActionUsage DeSerialize(JsonElement jsonElement, Seriali logger.LogDebug("the variantMembership Json property was not found in the ForLoopActionUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.ForLoopActionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ForLoopActionUsage: { 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 ForLoopActionUsage: { 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 ForLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the ForLoopActionUsage: { 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 ForLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ForLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the ForLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the ForLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the ForLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the ForLoopActionUsage: { 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 ForLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the ForLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the ForLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the ForLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ForLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the ForLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the ForLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ForLoopActionUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ForLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the ForLoopActionUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ForkNodeDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ForkNodeDeSerializer.cs index ff52253f..59c22f4a 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ForkNodeDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ForkNodeDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ForkNodeDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IForkNode DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IForkNode DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ForkNodeDeSerializer"); @@ -85,6 +88,33 @@ internal static IForkNode DeSerialize(JsonElement jsonElement, SerializationMode } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.ForkNode dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actionDefinition"u8, out var actionDefinitionProperty)) { foreach (var arrayItem in actionDefinitionProperty.EnumerateArray()) @@ -2156,8 +2186,278 @@ internal static IForkNode DeSerialize(JsonElement jsonElement, SerializationMode logger.LogDebug("the variantMembership Json property was not found in the ForkNode: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.ForkNode dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ForkNode: { 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 ForkNode: { 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 ForkNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the ForkNode: { 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 ForkNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ForkNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the ForkNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the ForkNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the ForkNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the ForkNode: { 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 ForkNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the ForkNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the ForkNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the ForkNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ForkNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the ForkNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the ForkNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ForkNode: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ForkNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the ForkNode: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FramedConcernMembershipDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FramedConcernMembershipDeSerializer.cs index 5ca7e477..092130f3 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FramedConcernMembershipDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FramedConcernMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class FramedConcernMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IFramedConcernMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IFramedConcernMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("FramedConcernMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IFramedConcernMembership DeSerialize(JsonElement jsonElement, Se } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.FramedConcernMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -582,8 +612,202 @@ internal static IFramedConcernMembership DeSerialize(JsonElement jsonElement, Se logger.LogDebug("the visibility Json property was not found in the FramedConcernMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.FramedConcernMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 FramedConcernMembership: { 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 FramedConcernMembership: { 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 FramedConcernMembership: { 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 FramedConcernMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the FramedConcernMembership: { 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 FramedConcernMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("kind"u8, out var kindProperty)) + { + dtoInstance.Kind = RequirementConstraintKindDeSerializer.Deserialize(kindProperty.GetString()); + } + else + { + logger.LogDebug("the kind Json property was not found in the FramedConcernMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the FramedConcernMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the FramedConcernMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the FramedConcernMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the FramedConcernMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the FramedConcernMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FunctionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FunctionDeSerializer.cs index ed962798..82f28ef3 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FunctionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/FunctionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class FunctionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IFunction DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IFunction DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("FunctionDeSerializer"); @@ -85,6 +88,33 @@ internal static IFunction DeSerialize(JsonElement jsonElement, SerializationMode } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Functions.Function dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1062,8 +1092,152 @@ internal static IFunction DeSerialize(JsonElement jsonElement, SerializationMode logger.LogDebug("the unioningType Json property was not found in the Function: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Functions.Function dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Function: { 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 Function: { 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 Function: { 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 Function: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Function: { 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 Function: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Function: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Function: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Function: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/IfActionUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/IfActionUsageDeSerializer.cs index dfe0dcca..77e01b94 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/IfActionUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/IfActionUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class IfActionUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IIfActionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IIfActionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("IfActionUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IIfActionUsage DeSerialize(JsonElement jsonElement, Serializatio } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.IfActionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actionDefinition"u8, out var actionDefinitionProperty)) { foreach (var arrayItem in actionDefinitionProperty.EnumerateArray()) @@ -2230,8 +2260,278 @@ internal static IIfActionUsage DeSerialize(JsonElement jsonElement, Serializatio logger.LogDebug("the variantMembership Json property was not found in the IfActionUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.IfActionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 IfActionUsage: { 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 IfActionUsage: { 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 IfActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the IfActionUsage: { 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 IfActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the IfActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the IfActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the IfActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the IfActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the IfActionUsage: { 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 IfActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the IfActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the IfActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the IfActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the IfActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the IfActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the IfActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the IfActionUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the IfActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the IfActionUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/IncludeUseCaseUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/IncludeUseCaseUsageDeSerializer.cs index 855e1ed6..30fd2536 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/IncludeUseCaseUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/IncludeUseCaseUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class IncludeUseCaseUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IIncludeUseCaseUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IIncludeUseCaseUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("IncludeUseCaseUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IIncludeUseCaseUsage DeSerialize(JsonElement jsonElement, Serial } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.UseCases.IncludeUseCaseUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actorParameter"u8, out var actorParameterProperty)) { foreach (var arrayItem in actorParameterProperty.EnumerateArray()) @@ -2311,8 +2341,278 @@ internal static IIncludeUseCaseUsage DeSerialize(JsonElement jsonElement, Serial logger.LogDebug("the variantMembership Json property was not found in the IncludeUseCaseUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.UseCases.IncludeUseCaseUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 IncludeUseCaseUsage: { 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 IncludeUseCaseUsage: { 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 IncludeUseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the IncludeUseCaseUsage: { 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 IncludeUseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the IncludeUseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the IncludeUseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the IncludeUseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the IncludeUseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the IncludeUseCaseUsage: { 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 IncludeUseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the IncludeUseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the IncludeUseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the IncludeUseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the IncludeUseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the IncludeUseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the IncludeUseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the IncludeUseCaseUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the IncludeUseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the IncludeUseCaseUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/IndexExpressionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/IndexExpressionDeSerializer.cs index dd1bedcd..e1e5c929 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/IndexExpressionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/IndexExpressionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class IndexExpressionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IIndexExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IIndexExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("IndexExpressionDeSerializer"); @@ -85,6 +88,33 @@ internal static IIndexExpression DeSerialize(JsonElement jsonElement, Serializat } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.IndexExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1539,8 +1569,271 @@ internal static IIndexExpression DeSerialize(JsonElement jsonElement, Serializat logger.LogDebug("the unioningType Json property was not found in the IndexExpression: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.IndexExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 IndexExpression: { 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 IndexExpression: { 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 IndexExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the IndexExpression: { 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 IndexExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the IndexExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the IndexExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the IndexExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the IndexExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the IndexExpression: { 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 IndexExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the IndexExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the IndexExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the IndexExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the IndexExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the IndexExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("operator"u8, out var operatorProperty)) + { + var propertyValue = operatorProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Operator = propertyValue; + } + } + else + { + logger.LogDebug("the operator Json property was not found in the IndexExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the IndexExpression: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the IndexExpression: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InteractionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InteractionDeSerializer.cs index 6154990d..e952ad63 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InteractionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InteractionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class InteractionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IInteraction DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IInteraction DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("InteractionDeSerializer"); @@ -85,6 +88,33 @@ internal static IInteraction DeSerialize(JsonElement jsonElement, SerializationM } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Interactions.Interaction dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1125,8 +1155,208 @@ internal static IInteraction DeSerialize(JsonElement jsonElement, SerializationM logger.LogDebug("the unioningType Json property was not found in the Interaction: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Interactions.Interaction dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Interaction: { 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 Interaction: { 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 Interaction: { 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 Interaction: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Interaction: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Interaction: { 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 Interaction: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Interaction: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Interaction: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Interaction: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Interaction: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Interaction: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InterfaceDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InterfaceDefinitionDeSerializer.cs index 3f423c5e..789f252a 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InterfaceDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InterfaceDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class InterfaceDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IInterfaceDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IInterfaceDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("InterfaceDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IInterfaceDefinition DeSerialize(JsonElement jsonElement, Serial } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Interfaces.InterfaceDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1749,8 +1779,232 @@ internal static IInterfaceDefinition DeSerialize(JsonElement jsonElement, Serial logger.LogDebug("the variantMembership Json property was not found in the InterfaceDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Interfaces.InterfaceDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 InterfaceDefinition: { 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 InterfaceDefinition: { 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 InterfaceDefinition: { 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 InterfaceDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the InterfaceDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the InterfaceDefinition: { 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 InterfaceDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the InterfaceDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the InterfaceDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the InterfaceDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the InterfaceDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the InterfaceDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the InterfaceDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the InterfaceDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InterfaceUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InterfaceUsageDeSerializer.cs index 6b5935f4..eed14b61 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InterfaceUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InterfaceUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class InterfaceUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IInterfaceUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IInterfaceUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("InterfaceUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IInterfaceUsage DeSerialize(JsonElement jsonElement, Serializati } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Interfaces.InterfaceUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2360,8 +2390,334 @@ internal static IInterfaceUsage DeSerialize(JsonElement jsonElement, Serializati logger.LogDebug("the variantMembership Json property was not found in the InterfaceUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Interfaces.InterfaceUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 InterfaceUsage: { 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 InterfaceUsage: { 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 InterfaceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the InterfaceUsage: { 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 InterfaceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the InterfaceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the InterfaceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the InterfaceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the InterfaceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the InterfaceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the InterfaceUsage: { 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 InterfaceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the InterfaceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the InterfaceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the InterfaceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the InterfaceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the InterfaceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the InterfaceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the InterfaceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the InterfaceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the InterfaceUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the InterfaceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the InterfaceUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/IntersectingDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/IntersectingDeSerializer.cs index 548c74a1..1a1f30c9 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/IntersectingDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/IntersectingDeSerializer.cs @@ -49,13 +49,16 @@ internal static class IntersectingDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IIntersecting DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IIntersecting DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("IntersectingDeSerializer"); @@ -85,6 +88,33 @@ internal static IIntersecting DeSerialize(JsonElement jsonElement, Serialization } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Types.Intersecting dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -507,8 +537,209 @@ internal static IIntersecting DeSerialize(JsonElement jsonElement, Serialization logger.LogDebug("the typeIntersected Json property was not found in the Intersecting: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Types.Intersecting dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Intersecting: { 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 Intersecting: { 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 Intersecting: { 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 Intersecting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("intersectingType"u8, out var intersectingTypeProperty)) + { + if (intersectingTypeProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.IntersectingType = Guid.Empty; + logger.LogDebug($"the Intersecting.IntersectingType property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (intersectingTypeProperty.TryGetProperty("@id"u8, out var intersectingTypeExternalIdProperty)) + { + var propertyValue = intersectingTypeExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.IntersectingType = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the intersectingType Json property was not found in the Intersecting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Intersecting: { 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 Intersecting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Intersecting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Intersecting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Intersecting: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Intersecting: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InvariantDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InvariantDeSerializer.cs index a0b1b176..be6284b7 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InvariantDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InvariantDeSerializer.cs @@ -49,13 +49,16 @@ internal static class InvariantDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IInvariant DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IInvariant DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("InvariantDeSerializer"); @@ -85,6 +88,33 @@ internal static IInvariant DeSerialize(JsonElement jsonElement, SerializationMod } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Functions.Invariant dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1492,8 +1522,269 @@ internal static IInvariant DeSerialize(JsonElement jsonElement, SerializationMod logger.LogDebug("the unioningType Json property was not found in the Invariant: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Functions.Invariant dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Invariant: { 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 Invariant: { 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 Invariant: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the Invariant: { 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 Invariant: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Invariant: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the Invariant: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the Invariant: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the Invariant: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the Invariant: { 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 Invariant: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isNegated"u8, out var isNegatedProperty)) + { + if (isNegatedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsNegated = isNegatedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isNegated Json property was not found in the Invariant: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the Invariant: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the Invariant: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Invariant: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the Invariant: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the Invariant: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Invariant: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Invariant: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InvocationExpressionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InvocationExpressionDeSerializer.cs index 36b3e026..edff0d8a 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InvocationExpressionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/InvocationExpressionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class InvocationExpressionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IInvocationExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IInvocationExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("InvocationExpressionDeSerializer"); @@ -85,6 +88,33 @@ internal static IInvocationExpression DeSerialize(JsonElement jsonElement, Seria } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.InvocationExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1525,8 +1555,257 @@ internal static IInvocationExpression DeSerialize(JsonElement jsonElement, Seria logger.LogDebug("the unioningType Json property was not found in the InvocationExpression: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.InvocationExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 InvocationExpression: { 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 InvocationExpression: { 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 InvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the InvocationExpression: { 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 InvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the InvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the InvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the InvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the InvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the InvocationExpression: { 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 InvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the InvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the InvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the InvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the InvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the InvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the InvocationExpression: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the InvocationExpression: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ItemDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ItemDefinitionDeSerializer.cs index 40224252..17f403e8 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ItemDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ItemDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ItemDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IItemDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IItemDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ItemDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IItemDefinition DeSerialize(JsonElement jsonElement, Serializati } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Items.ItemDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1629,8 +1659,176 @@ internal static IItemDefinition DeSerialize(JsonElement jsonElement, Serializati logger.LogDebug("the variantMembership Json property was not found in the ItemDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Items.ItemDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ItemDefinition: { 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 ItemDefinition: { 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 ItemDefinition: { 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 ItemDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ItemDefinition: { 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 ItemDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the ItemDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ItemDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the ItemDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ItemDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ItemDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ItemUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ItemUsageDeSerializer.cs index 167e8def..3fbfa720 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ItemUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ItemUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ItemUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IItemUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IItemUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ItemUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IItemUsage DeSerialize(JsonElement jsonElement, SerializationMod } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Items.ItemUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2176,8 +2206,278 @@ internal static IItemUsage DeSerialize(JsonElement jsonElement, SerializationMod logger.LogDebug("the variantMembership Json property was not found in the ItemUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Items.ItemUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ItemUsage: { 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 ItemUsage: { 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 ItemUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the ItemUsage: { 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 ItemUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ItemUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the ItemUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the ItemUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the ItemUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the ItemUsage: { 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 ItemUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the ItemUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the ItemUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the ItemUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ItemUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the ItemUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the ItemUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ItemUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ItemUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the ItemUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/JoinNodeDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/JoinNodeDeSerializer.cs index f347d8ab..c785c6a4 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/JoinNodeDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/JoinNodeDeSerializer.cs @@ -49,13 +49,16 @@ internal static class JoinNodeDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IJoinNode DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IJoinNode DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("JoinNodeDeSerializer"); @@ -85,6 +88,33 @@ internal static IJoinNode DeSerialize(JsonElement jsonElement, SerializationMode } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.JoinNode dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actionDefinition"u8, out var actionDefinitionProperty)) { foreach (var arrayItem in actionDefinitionProperty.EnumerateArray()) @@ -2156,8 +2186,278 @@ internal static IJoinNode DeSerialize(JsonElement jsonElement, SerializationMode logger.LogDebug("the variantMembership Json property was not found in the JoinNode: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.JoinNode dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 JoinNode: { 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 JoinNode: { 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 JoinNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the JoinNode: { 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 JoinNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the JoinNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the JoinNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the JoinNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the JoinNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the JoinNode: { 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 JoinNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the JoinNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the JoinNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the JoinNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the JoinNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the JoinNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the JoinNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the JoinNode: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the JoinNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the JoinNode: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LibraryPackageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LibraryPackageDeSerializer.cs index 93912ad0..25700628 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LibraryPackageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LibraryPackageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class LibraryPackageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ILibraryPackage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ILibraryPackage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("LibraryPackageDeSerializer"); @@ -85,6 +88,33 @@ internal static ILibraryPackage DeSerialize(JsonElement jsonElement, Serializati } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Packages.LibraryPackage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -533,8 +563,140 @@ internal static ILibraryPackage DeSerialize(JsonElement jsonElement, Serializati logger.LogDebug("the textualRepresentation Json property was not found in the LibraryPackage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Packages.LibraryPackage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 LibraryPackage: { 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 LibraryPackage: { 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 LibraryPackage: { 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 LibraryPackage: { 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 LibraryPackage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isStandard"u8, out var isStandardProperty)) + { + if (isStandardProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsStandard = isStandardProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isStandard Json property was not found in the LibraryPackage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the LibraryPackage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the LibraryPackage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralBooleanDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralBooleanDeSerializer.cs index 3c6697d6..2016140e 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralBooleanDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralBooleanDeSerializer.cs @@ -49,13 +49,16 @@ internal static class LiteralBooleanDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ILiteralBoolean DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ILiteralBoolean DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("LiteralBooleanDeSerializer"); @@ -85,6 +88,33 @@ internal static ILiteralBoolean DeSerialize(JsonElement jsonElement, Serializati } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.LiteralBoolean dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1492,8 +1522,269 @@ internal static ILiteralBoolean DeSerialize(JsonElement jsonElement, Serializati logger.LogDebug("the value Json property was not found in the LiteralBoolean: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.LiteralBoolean dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 LiteralBoolean: { 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 LiteralBoolean: { 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 LiteralBoolean: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the LiteralBoolean: { 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 LiteralBoolean: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the LiteralBoolean: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the LiteralBoolean: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the LiteralBoolean: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the LiteralBoolean: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the LiteralBoolean: { 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 LiteralBoolean: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the LiteralBoolean: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the LiteralBoolean: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the LiteralBoolean: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the LiteralBoolean: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the LiteralBoolean: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the LiteralBoolean: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the LiteralBoolean: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) + { + if (valueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.Value = valueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the value Json property was not found in the LiteralBoolean: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralExpressionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralExpressionDeSerializer.cs index 51ab2a76..cbbbea97 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralExpressionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralExpressionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class LiteralExpressionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ILiteralExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ILiteralExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("LiteralExpressionDeSerializer"); @@ -85,6 +88,33 @@ internal static ILiteralExpression DeSerialize(JsonElement jsonElement, Serializ } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.LiteralExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1480,8 +1510,257 @@ internal static ILiteralExpression DeSerialize(JsonElement jsonElement, Serializ logger.LogDebug("the unioningType Json property was not found in the LiteralExpression: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.LiteralExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 LiteralExpression: { 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 LiteralExpression: { 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 LiteralExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the LiteralExpression: { 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 LiteralExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the LiteralExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the LiteralExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the LiteralExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the LiteralExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the LiteralExpression: { 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 LiteralExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the LiteralExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the LiteralExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the LiteralExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the LiteralExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the LiteralExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the LiteralExpression: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the LiteralExpression: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralInfinityDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralInfinityDeSerializer.cs index 9a08669a..fff807a4 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralInfinityDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralInfinityDeSerializer.cs @@ -49,13 +49,16 @@ internal static class LiteralInfinityDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ILiteralInfinity DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ILiteralInfinity DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("LiteralInfinityDeSerializer"); @@ -85,6 +88,33 @@ internal static ILiteralInfinity DeSerialize(JsonElement jsonElement, Serializat } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.LiteralInfinity dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1480,8 +1510,257 @@ internal static ILiteralInfinity DeSerialize(JsonElement jsonElement, Serializat logger.LogDebug("the unioningType Json property was not found in the LiteralInfinity: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.LiteralInfinity dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 LiteralInfinity: { 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 LiteralInfinity: { 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 LiteralInfinity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the LiteralInfinity: { 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 LiteralInfinity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the LiteralInfinity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the LiteralInfinity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the LiteralInfinity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the LiteralInfinity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the LiteralInfinity: { 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 LiteralInfinity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the LiteralInfinity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the LiteralInfinity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the LiteralInfinity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the LiteralInfinity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the LiteralInfinity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the LiteralInfinity: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the LiteralInfinity: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralIntegerDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralIntegerDeSerializer.cs index 517fdfb8..ae5d15d2 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralIntegerDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralIntegerDeSerializer.cs @@ -49,13 +49,16 @@ internal static class LiteralIntegerDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ILiteralInteger DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ILiteralInteger DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("LiteralIntegerDeSerializer"); @@ -85,6 +88,33 @@ internal static ILiteralInteger DeSerialize(JsonElement jsonElement, Serializati } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.LiteralInteger dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1489,8 +1519,266 @@ internal static ILiteralInteger DeSerialize(JsonElement jsonElement, Serializati logger.LogDebug("the value Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.LiteralInteger dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 LiteralInteger: { 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 LiteralInteger: { 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 LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the LiteralInteger: { 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 LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the LiteralInteger: { 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 LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the LiteralInteger: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) + { + dtoInstance.Value = valueProperty.GetInt32(); + } + else + { + logger.LogDebug("the value Json property was not found in the LiteralInteger: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralRationalDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralRationalDeSerializer.cs index 9215456a..3db0f53a 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralRationalDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralRationalDeSerializer.cs @@ -49,13 +49,16 @@ internal static class LiteralRationalDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ILiteralRational DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ILiteralRational DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("LiteralRationalDeSerializer"); @@ -85,6 +88,33 @@ internal static ILiteralRational DeSerialize(JsonElement jsonElement, Serializat } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.LiteralRational dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1489,8 +1519,266 @@ internal static ILiteralRational DeSerialize(JsonElement jsonElement, Serializat logger.LogDebug("the value Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.LiteralRational dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 LiteralRational: { 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 LiteralRational: { 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 LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the LiteralRational: { 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 LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the LiteralRational: { 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 LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the LiteralRational: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) + { + dtoInstance.Value = valueProperty.GetDouble(); + } + else + { + logger.LogDebug("the value Json property was not found in the LiteralRational: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralStringDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralStringDeSerializer.cs index 2feba9e8..064feb50 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralStringDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/LiteralStringDeSerializer.cs @@ -49,13 +49,16 @@ internal static class LiteralStringDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ILiteralString DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ILiteralString DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("LiteralStringDeSerializer"); @@ -85,6 +88,33 @@ internal static ILiteralString DeSerialize(JsonElement jsonElement, Serializatio } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.LiteralString dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1494,8 +1524,271 @@ internal static ILiteralString DeSerialize(JsonElement jsonElement, Serializatio logger.LogDebug("the value Json property was not found in the LiteralString: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.LiteralString dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 LiteralString: { 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 LiteralString: { 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 LiteralString: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the LiteralString: { 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 LiteralString: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the LiteralString: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the LiteralString: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the LiteralString: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the LiteralString: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the LiteralString: { 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 LiteralString: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the LiteralString: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the LiteralString: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the LiteralString: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the LiteralString: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the LiteralString: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the LiteralString: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the LiteralString: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("value"u8, out var valueProperty)) + { + var propertyValue = valueProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Value = propertyValue; + } + } + else + { + logger.LogDebug("the value Json property was not found in the LiteralString: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MembershipDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MembershipDeSerializer.cs index dc72c218..40e567b0 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MembershipDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class MembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("MembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IMembership DeSerialize(JsonElement jsonElement, SerializationMo } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Root.Namespaces.Membership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -548,8 +578,236 @@ internal static IMembership DeSerialize(JsonElement jsonElement, SerializationMo logger.LogDebug("the visibility Json property was not found in the Membership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Root.Namespaces.Membership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Membership: { 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 Membership: { 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 Membership: { 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 Membership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Membership: { 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 Membership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("memberElement"u8, out var memberElementProperty)) + { + if (memberElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.MemberElement = Guid.Empty; + logger.LogDebug($"the Membership.MemberElement property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (memberElementProperty.TryGetProperty("@id"u8, out var memberElementExternalIdProperty)) + { + var propertyValue = memberElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.MemberElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the memberElement Json property was not found in the Membership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("memberName"u8, out var memberNameProperty)) + { + dtoInstance.MemberName = memberNameProperty.GetString(); + } + else + { + logger.LogDebug("the memberName Json property was not found in the Membership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("memberShortName"u8, out var memberShortNameProperty)) + { + dtoInstance.MemberShortName = memberShortNameProperty.GetString(); + } + else + { + logger.LogDebug("the memberShortName Json property was not found in the Membership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Membership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Membership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Membership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Membership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the Membership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MembershipExposeDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MembershipExposeDeSerializer.cs index 30ab3e5d..836c640d 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MembershipExposeDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MembershipExposeDeSerializer.cs @@ -49,13 +49,16 @@ internal static class MembershipExposeDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IMembershipExpose DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IMembershipExpose DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("MembershipExposeDeSerializer"); @@ -85,6 +88,33 @@ internal static IMembershipExpose DeSerialize(JsonElement jsonElement, Serializa } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Views.MembershipExpose dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -565,8 +595,242 @@ internal static IMembershipExpose DeSerialize(JsonElement jsonElement, Serializa logger.LogDebug("the visibility Json property was not found in the MembershipExpose: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Views.MembershipExpose dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 MembershipExpose: { 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 MembershipExpose: { 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 MembershipExpose: { 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 MembershipExpose: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("importedMembership"u8, out var importedMembershipProperty)) + { + if (importedMembershipProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.ImportedMembership = Guid.Empty; + logger.LogDebug($"the MembershipExpose.ImportedMembership property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (importedMembershipProperty.TryGetProperty("@id"u8, out var importedMembershipExternalIdProperty)) + { + var propertyValue = importedMembershipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.ImportedMembership = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the importedMembership Json property was not found in the MembershipExpose: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the MembershipExpose: { 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 MembershipExpose: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImportAll"u8, out var isImportAllProperty)) + { + if (isImportAllProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImportAll = isImportAllProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImportAll Json property was not found in the MembershipExpose: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isRecursive"u8, out var isRecursiveProperty)) + { + if (isRecursiveProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsRecursive = isRecursiveProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isRecursive Json property was not found in the MembershipExpose: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the MembershipExpose: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the MembershipExpose: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the MembershipExpose: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the MembershipExpose: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the MembershipExpose: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MembershipImportDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MembershipImportDeSerializer.cs index cc114a08..828b7fd9 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MembershipImportDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MembershipImportDeSerializer.cs @@ -49,13 +49,16 @@ internal static class MembershipImportDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IMembershipImport DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IMembershipImport DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("MembershipImportDeSerializer"); @@ -85,6 +88,33 @@ internal static IMembershipImport DeSerialize(JsonElement jsonElement, Serializa } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Root.Namespaces.MembershipImport dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -565,8 +595,242 @@ internal static IMembershipImport DeSerialize(JsonElement jsonElement, Serializa logger.LogDebug("the visibility Json property was not found in the MembershipImport: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Root.Namespaces.MembershipImport dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 MembershipImport: { 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 MembershipImport: { 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 MembershipImport: { 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 MembershipImport: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("importedMembership"u8, out var importedMembershipProperty)) + { + if (importedMembershipProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.ImportedMembership = Guid.Empty; + logger.LogDebug($"the MembershipImport.ImportedMembership property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (importedMembershipProperty.TryGetProperty("@id"u8, out var importedMembershipExternalIdProperty)) + { + var propertyValue = importedMembershipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.ImportedMembership = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the importedMembership Json property was not found in the MembershipImport: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the MembershipImport: { 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 MembershipImport: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImportAll"u8, out var isImportAllProperty)) + { + if (isImportAllProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImportAll = isImportAllProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImportAll Json property was not found in the MembershipImport: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isRecursive"u8, out var isRecursiveProperty)) + { + if (isRecursiveProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsRecursive = isRecursiveProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isRecursive Json property was not found in the MembershipImport: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the MembershipImport: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the MembershipImport: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the MembershipImport: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the MembershipImport: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the MembershipImport: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MergeNodeDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MergeNodeDeSerializer.cs index e188ae32..181e3113 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MergeNodeDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MergeNodeDeSerializer.cs @@ -49,13 +49,16 @@ internal static class MergeNodeDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IMergeNode DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IMergeNode DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("MergeNodeDeSerializer"); @@ -85,6 +88,33 @@ internal static IMergeNode DeSerialize(JsonElement jsonElement, SerializationMod } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.MergeNode dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actionDefinition"u8, out var actionDefinitionProperty)) { foreach (var arrayItem in actionDefinitionProperty.EnumerateArray()) @@ -2156,8 +2186,278 @@ internal static IMergeNode DeSerialize(JsonElement jsonElement, SerializationMod logger.LogDebug("the variantMembership Json property was not found in the MergeNode: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.MergeNode dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 MergeNode: { 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 MergeNode: { 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 MergeNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the MergeNode: { 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 MergeNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the MergeNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the MergeNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the MergeNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the MergeNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the MergeNode: { 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 MergeNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the MergeNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the MergeNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the MergeNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the MergeNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the MergeNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the MergeNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the MergeNode: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the MergeNode: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the MergeNode: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetaclassDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetaclassDeSerializer.cs index ef68af3e..50212e9e 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetaclassDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetaclassDeSerializer.cs @@ -49,13 +49,16 @@ internal static class MetaclassDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IMetaclass DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IMetaclass DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("MetaclassDeSerializer"); @@ -85,6 +88,33 @@ internal static IMetaclass DeSerialize(JsonElement jsonElement, SerializationMod } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Metadata.Metaclass dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -985,8 +1015,152 @@ internal static IMetaclass DeSerialize(JsonElement jsonElement, SerializationMod logger.LogDebug("the unioningType Json property was not found in the Metaclass: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Metadata.Metaclass dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Metaclass: { 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 Metaclass: { 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 Metaclass: { 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 Metaclass: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Metaclass: { 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 Metaclass: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Metaclass: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Metaclass: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Metaclass: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetadataAccessExpressionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetadataAccessExpressionDeSerializer.cs index 28825206..ef7216ba 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetadataAccessExpressionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetadataAccessExpressionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class MetadataAccessExpressionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IMetadataAccessExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IMetadataAccessExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("MetadataAccessExpressionDeSerializer"); @@ -85,6 +88,33 @@ internal static IMetadataAccessExpression DeSerialize(JsonElement jsonElement, S } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.MetadataAccessExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1505,8 +1535,257 @@ internal static IMetadataAccessExpression DeSerialize(JsonElement jsonElement, S logger.LogDebug("the unioningType Json property was not found in the MetadataAccessExpression: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.MetadataAccessExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 MetadataAccessExpression: { 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 MetadataAccessExpression: { 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 MetadataAccessExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the MetadataAccessExpression: { 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 MetadataAccessExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the MetadataAccessExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the MetadataAccessExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the MetadataAccessExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the MetadataAccessExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the MetadataAccessExpression: { 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 MetadataAccessExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the MetadataAccessExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the MetadataAccessExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the MetadataAccessExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the MetadataAccessExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the MetadataAccessExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the MetadataAccessExpression: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the MetadataAccessExpression: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetadataDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetadataDefinitionDeSerializer.cs index 3a6f6948..46ec87ee 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetadataDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetadataDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class MetadataDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IMetadataDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IMetadataDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("MetadataDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IMetadataDefinition DeSerialize(JsonElement jsonElement, Seriali } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Metadata.MetadataDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1629,8 +1659,176 @@ internal static IMetadataDefinition DeSerialize(JsonElement jsonElement, Seriali logger.LogDebug("the variantMembership Json property was not found in the MetadataDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Metadata.MetadataDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 MetadataDefinition: { 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 MetadataDefinition: { 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 MetadataDefinition: { 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 MetadataDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the MetadataDefinition: { 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 MetadataDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the MetadataDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the MetadataDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the MetadataDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the MetadataDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the MetadataDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetadataFeatureDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetadataFeatureDeSerializer.cs index 0c3fb90b..e374a3dd 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetadataFeatureDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetadataFeatureDeSerializer.cs @@ -49,13 +49,16 @@ internal static class MetadataFeatureDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IMetadataFeature DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IMetadataFeature DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("MetadataFeatureDeSerializer"); @@ -85,6 +88,33 @@ internal static IMetadataFeature DeSerialize(JsonElement jsonElement, Serializat } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Metadata.MetadataFeature dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1527,8 +1557,257 @@ internal static IMetadataFeature DeSerialize(JsonElement jsonElement, Serializat logger.LogDebug("the unioningType Json property was not found in the MetadataFeature: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Metadata.MetadataFeature dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 MetadataFeature: { 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 MetadataFeature: { 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 MetadataFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the MetadataFeature: { 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 MetadataFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the MetadataFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the MetadataFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the MetadataFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the MetadataFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the MetadataFeature: { 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 MetadataFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the MetadataFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the MetadataFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the MetadataFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the MetadataFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the MetadataFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the MetadataFeature: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the MetadataFeature: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetadataUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetadataUsageDeSerializer.cs index 78239bdb..c7989f27 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetadataUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MetadataUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class MetadataUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IMetadataUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IMetadataUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("MetadataUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IMetadataUsage DeSerialize(JsonElement jsonElement, Serializatio } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Metadata.MetadataUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2264,8 +2294,278 @@ internal static IMetadataUsage DeSerialize(JsonElement jsonElement, Serializatio logger.LogDebug("the variantMembership Json property was not found in the MetadataUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Metadata.MetadataUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 MetadataUsage: { 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 MetadataUsage: { 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 MetadataUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the MetadataUsage: { 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 MetadataUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the MetadataUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the MetadataUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the MetadataUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the MetadataUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the MetadataUsage: { 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 MetadataUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the MetadataUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the MetadataUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the MetadataUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the MetadataUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the MetadataUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the MetadataUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the MetadataUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the MetadataUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the MetadataUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MultiplicityDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MultiplicityDeSerializer.cs index e94e3067..772756d5 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MultiplicityDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MultiplicityDeSerializer.cs @@ -49,13 +49,16 @@ internal static class MultiplicityDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IMultiplicity DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IMultiplicity DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("MultiplicityDeSerializer"); @@ -85,6 +88,33 @@ internal static IMultiplicity DeSerialize(JsonElement jsonElement, Serialization } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Types.Multiplicity dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1419,8 +1449,257 @@ internal static IMultiplicity DeSerialize(JsonElement jsonElement, Serialization logger.LogDebug("the unioningType Json property was not found in the Multiplicity: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Types.Multiplicity dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Multiplicity: { 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 Multiplicity: { 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 Multiplicity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the Multiplicity: { 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 Multiplicity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Multiplicity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the Multiplicity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the Multiplicity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the Multiplicity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the Multiplicity: { 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 Multiplicity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the Multiplicity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the Multiplicity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Multiplicity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the Multiplicity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the Multiplicity: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Multiplicity: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Multiplicity: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MultiplicityRangeDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MultiplicityRangeDeSerializer.cs index 0dadc054..bdb53731 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MultiplicityRangeDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/MultiplicityRangeDeSerializer.cs @@ -49,13 +49,16 @@ internal static class MultiplicityRangeDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IMultiplicityRange DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IMultiplicityRange DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("MultiplicityRangeDeSerializer"); @@ -85,6 +88,33 @@ internal static IMultiplicityRange DeSerialize(JsonElement jsonElement, Serializ } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Multiplicities.MultiplicityRange dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1488,8 +1518,257 @@ internal static IMultiplicityRange DeSerialize(JsonElement jsonElement, Serializ logger.LogDebug("the upperBound Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Multiplicities.MultiplicityRange dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 MultiplicityRange: { 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 MultiplicityRange: { 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 MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the MultiplicityRange: { 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 MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the MultiplicityRange: { 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 MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the MultiplicityRange: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the MultiplicityRange: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/NamespaceDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/NamespaceDeSerializer.cs index cbf032fd..82a41583 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/NamespaceDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/NamespaceDeSerializer.cs @@ -49,13 +49,16 @@ internal static class NamespaceDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static INamespace DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static INamespace DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("NamespaceDeSerializer"); @@ -85,6 +88,33 @@ internal static INamespace DeSerialize(JsonElement jsonElement, SerializationMod } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Root.Namespaces.Namespace dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -501,8 +531,128 @@ internal static INamespace DeSerialize(JsonElement jsonElement, SerializationMod logger.LogDebug("the textualRepresentation Json property was not found in the Namespace: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Root.Namespaces.Namespace dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Namespace: { 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 Namespace: { 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 Namespace: { 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 Namespace: { 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 Namespace: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Namespace: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Namespace: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/NamespaceExposeDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/NamespaceExposeDeSerializer.cs index ed475220..15401554 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/NamespaceExposeDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/NamespaceExposeDeSerializer.cs @@ -49,13 +49,16 @@ internal static class NamespaceExposeDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static INamespaceExpose DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static INamespaceExpose DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("NamespaceExposeDeSerializer"); @@ -85,6 +88,33 @@ internal static INamespaceExpose DeSerialize(JsonElement jsonElement, Serializat } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Views.NamespaceExpose dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -565,8 +595,242 @@ internal static INamespaceExpose DeSerialize(JsonElement jsonElement, Serializat logger.LogDebug("the visibility Json property was not found in the NamespaceExpose: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Views.NamespaceExpose dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 NamespaceExpose: { 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 NamespaceExpose: { 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 NamespaceExpose: { 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 NamespaceExpose: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("importedNamespace"u8, out var importedNamespaceProperty)) + { + if (importedNamespaceProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.ImportedNamespace = Guid.Empty; + logger.LogDebug($"the NamespaceExpose.ImportedNamespace property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (importedNamespaceProperty.TryGetProperty("@id"u8, out var importedNamespaceExternalIdProperty)) + { + var propertyValue = importedNamespaceExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.ImportedNamespace = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the importedNamespace Json property was not found in the NamespaceExpose: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the NamespaceExpose: { 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 NamespaceExpose: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImportAll"u8, out var isImportAllProperty)) + { + if (isImportAllProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImportAll = isImportAllProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImportAll Json property was not found in the NamespaceExpose: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isRecursive"u8, out var isRecursiveProperty)) + { + if (isRecursiveProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsRecursive = isRecursiveProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isRecursive Json property was not found in the NamespaceExpose: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the NamespaceExpose: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the NamespaceExpose: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the NamespaceExpose: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the NamespaceExpose: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the NamespaceExpose: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/NamespaceImportDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/NamespaceImportDeSerializer.cs index 43ba727a..4842257a 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/NamespaceImportDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/NamespaceImportDeSerializer.cs @@ -49,13 +49,16 @@ internal static class NamespaceImportDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static INamespaceImport DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static INamespaceImport DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("NamespaceImportDeSerializer"); @@ -85,6 +88,33 @@ internal static INamespaceImport DeSerialize(JsonElement jsonElement, Serializat } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Root.Namespaces.NamespaceImport dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -565,8 +595,242 @@ internal static INamespaceImport DeSerialize(JsonElement jsonElement, Serializat logger.LogDebug("the visibility Json property was not found in the NamespaceImport: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Root.Namespaces.NamespaceImport dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 NamespaceImport: { 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 NamespaceImport: { 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 NamespaceImport: { 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 NamespaceImport: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("importedNamespace"u8, out var importedNamespaceProperty)) + { + if (importedNamespaceProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.ImportedNamespace = Guid.Empty; + logger.LogDebug($"the NamespaceImport.ImportedNamespace property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (importedNamespaceProperty.TryGetProperty("@id"u8, out var importedNamespaceExternalIdProperty)) + { + var propertyValue = importedNamespaceExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.ImportedNamespace = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the importedNamespace Json property was not found in the NamespaceImport: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the NamespaceImport: { 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 NamespaceImport: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImportAll"u8, out var isImportAllProperty)) + { + if (isImportAllProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImportAll = isImportAllProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImportAll Json property was not found in the NamespaceImport: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isRecursive"u8, out var isRecursiveProperty)) + { + if (isRecursiveProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsRecursive = isRecursiveProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isRecursive Json property was not found in the NamespaceImport: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the NamespaceImport: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the NamespaceImport: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the NamespaceImport: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the NamespaceImport: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the NamespaceImport: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/NullExpressionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/NullExpressionDeSerializer.cs index 4028dd4c..0247d8a2 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/NullExpressionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/NullExpressionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class NullExpressionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static INullExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static INullExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("NullExpressionDeSerializer"); @@ -85,6 +88,33 @@ internal static INullExpression DeSerialize(JsonElement jsonElement, Serializati } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.NullExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1480,8 +1510,257 @@ internal static INullExpression DeSerialize(JsonElement jsonElement, Serializati logger.LogDebug("the unioningType Json property was not found in the NullExpression: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.NullExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 NullExpression: { 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 NullExpression: { 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 NullExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the NullExpression: { 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 NullExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the NullExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the NullExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the NullExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the NullExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the NullExpression: { 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 NullExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the NullExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the NullExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the NullExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the NullExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the NullExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the NullExpression: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the NullExpression: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ObjectiveMembershipDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ObjectiveMembershipDeSerializer.cs index 431d1e3b..07861c8a 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ObjectiveMembershipDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ObjectiveMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ObjectiveMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IObjectiveMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IObjectiveMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ObjectiveMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IObjectiveMembership DeSerialize(JsonElement jsonElement, Serial } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Cases.ObjectiveMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -548,8 +578,193 @@ internal static IObjectiveMembership DeSerialize(JsonElement jsonElement, Serial logger.LogDebug("the visibility Json property was not found in the ObjectiveMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Cases.ObjectiveMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ObjectiveMembership: { 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 ObjectiveMembership: { 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 ObjectiveMembership: { 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 ObjectiveMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the ObjectiveMembership: { 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 ObjectiveMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the ObjectiveMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ObjectiveMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the ObjectiveMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ObjectiveMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the ObjectiveMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/OccurrenceDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/OccurrenceDefinitionDeSerializer.cs index 1ba2aea1..77edfd96 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/OccurrenceDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/OccurrenceDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class OccurrenceDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IOccurrenceDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IOccurrenceDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("OccurrenceDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IOccurrenceDefinition DeSerialize(JsonElement jsonElement, Seria } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Occurrences.OccurrenceDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1629,8 +1659,176 @@ internal static IOccurrenceDefinition DeSerialize(JsonElement jsonElement, Seria logger.LogDebug("the variantMembership Json property was not found in the OccurrenceDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Occurrences.OccurrenceDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 OccurrenceDefinition: { 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 OccurrenceDefinition: { 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 OccurrenceDefinition: { 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 OccurrenceDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the OccurrenceDefinition: { 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 OccurrenceDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the OccurrenceDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the OccurrenceDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the OccurrenceDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the OccurrenceDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the OccurrenceDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/OccurrenceUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/OccurrenceUsageDeSerializer.cs index 3e5a8f33..ba0c6ad9 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/OccurrenceUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/OccurrenceUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class OccurrenceUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IOccurrenceUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IOccurrenceUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("OccurrenceUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IOccurrenceUsage DeSerialize(JsonElement jsonElement, Serializat } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Occurrences.OccurrenceUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2156,8 +2186,278 @@ internal static IOccurrenceUsage DeSerialize(JsonElement jsonElement, Serializat logger.LogDebug("the variantMembership Json property was not found in the OccurrenceUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Occurrences.OccurrenceUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 OccurrenceUsage: { 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 OccurrenceUsage: { 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 OccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the OccurrenceUsage: { 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 OccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the OccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the OccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the OccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the OccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the OccurrenceUsage: { 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 OccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the OccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the OccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the OccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the OccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the OccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the OccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the OccurrenceUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the OccurrenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the OccurrenceUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/OperatorExpressionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/OperatorExpressionDeSerializer.cs index 5264146b..c3d38722 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/OperatorExpressionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/OperatorExpressionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class OperatorExpressionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IOperatorExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IOperatorExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("OperatorExpressionDeSerializer"); @@ -85,6 +88,33 @@ internal static IOperatorExpression DeSerialize(JsonElement jsonElement, Seriali } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.OperatorExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1539,8 +1569,271 @@ internal static IOperatorExpression DeSerialize(JsonElement jsonElement, Seriali logger.LogDebug("the unioningType Json property was not found in the OperatorExpression: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.OperatorExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 OperatorExpression: { 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 OperatorExpression: { 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 OperatorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the OperatorExpression: { 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 OperatorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the OperatorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the OperatorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the OperatorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the OperatorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the OperatorExpression: { 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 OperatorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the OperatorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the OperatorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the OperatorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the OperatorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the OperatorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("operator"u8, out var operatorProperty)) + { + var propertyValue = operatorProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Operator = propertyValue; + } + } + else + { + logger.LogDebug("the operator Json property was not found in the OperatorExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the OperatorExpression: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the OperatorExpression: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/OwningMembershipDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/OwningMembershipDeSerializer.cs index b8b123b8..499ac7c3 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/OwningMembershipDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/OwningMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class OwningMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IOwningMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IOwningMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("OwningMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IOwningMembership DeSerialize(JsonElement jsonElement, Serializa } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Root.Namespaces.OwningMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -548,8 +578,193 @@ internal static IOwningMembership DeSerialize(JsonElement jsonElement, Serializa logger.LogDebug("the visibility Json property was not found in the OwningMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Root.Namespaces.OwningMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 OwningMembership: { 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 OwningMembership: { 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 OwningMembership: { 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 OwningMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the OwningMembership: { 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 OwningMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the OwningMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the OwningMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the OwningMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the OwningMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the OwningMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PackageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PackageDeSerializer.cs index baf674d1..fd64230f 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PackageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PackageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class PackageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IPackage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IPackage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("PackageDeSerializer"); @@ -85,6 +88,33 @@ internal static IPackage DeSerialize(JsonElement jsonElement, SerializationModeK } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Packages.Package dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -521,8 +551,128 @@ internal static IPackage DeSerialize(JsonElement jsonElement, SerializationModeK logger.LogDebug("the textualRepresentation Json property was not found in the Package: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Packages.Package dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Package: { 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 Package: { 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 Package: { 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 Package: { 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 Package: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Package: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Package: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ParameterMembershipDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ParameterMembershipDeSerializer.cs index 1cc4d534..889b2670 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ParameterMembershipDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ParameterMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ParameterMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IParameterMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IParameterMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ParameterMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IParameterMembership DeSerialize(JsonElement jsonElement, Serial } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Behaviors.ParameterMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -548,8 +578,193 @@ internal static IParameterMembership DeSerialize(JsonElement jsonElement, Serial logger.LogDebug("the visibility Json property was not found in the ParameterMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Behaviors.ParameterMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ParameterMembership: { 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 ParameterMembership: { 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 ParameterMembership: { 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 ParameterMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the ParameterMembership: { 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 ParameterMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the ParameterMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ParameterMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the ParameterMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ParameterMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the ParameterMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PartDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PartDefinitionDeSerializer.cs index 7f2ce3d0..13282fa9 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PartDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PartDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class PartDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IPartDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IPartDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("PartDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IPartDefinition DeSerialize(JsonElement jsonElement, Serializati } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Parts.PartDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1629,8 +1659,176 @@ internal static IPartDefinition DeSerialize(JsonElement jsonElement, Serializati logger.LogDebug("the variantMembership Json property was not found in the PartDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Parts.PartDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 PartDefinition: { 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 PartDefinition: { 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 PartDefinition: { 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 PartDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the PartDefinition: { 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 PartDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the PartDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the PartDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the PartDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the PartDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the PartDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PartUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PartUsageDeSerializer.cs index c57f954b..0643e6c4 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PartUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PartUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class PartUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IPartUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IPartUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("PartUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IPartUsage DeSerialize(JsonElement jsonElement, SerializationMod } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Parts.PartUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2196,8 +2226,278 @@ internal static IPartUsage DeSerialize(JsonElement jsonElement, SerializationMod logger.LogDebug("the variantMembership Json property was not found in the PartUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Parts.PartUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 PartUsage: { 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 PartUsage: { 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 PartUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the PartUsage: { 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 PartUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the PartUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the PartUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the PartUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the PartUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the PartUsage: { 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 PartUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the PartUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the PartUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the PartUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the PartUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the PartUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the PartUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the PartUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the PartUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the PartUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PayloadFeatureDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PayloadFeatureDeSerializer.cs index e9b6ac6c..7ed0d39f 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PayloadFeatureDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PayloadFeatureDeSerializer.cs @@ -49,13 +49,16 @@ internal static class PayloadFeatureDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IPayloadFeature DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IPayloadFeature DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("PayloadFeatureDeSerializer"); @@ -85,6 +88,33 @@ internal static IPayloadFeature DeSerialize(JsonElement jsonElement, Serializati } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Interactions.PayloadFeature dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1419,8 +1449,257 @@ internal static IPayloadFeature DeSerialize(JsonElement jsonElement, Serializati logger.LogDebug("the unioningType Json property was not found in the PayloadFeature: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Interactions.PayloadFeature dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 PayloadFeature: { 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 PayloadFeature: { 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 PayloadFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the PayloadFeature: { 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 PayloadFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the PayloadFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the PayloadFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the PayloadFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the PayloadFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the PayloadFeature: { 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 PayloadFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the PayloadFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the PayloadFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the PayloadFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the PayloadFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the PayloadFeature: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the PayloadFeature: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the PayloadFeature: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PerformActionUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PerformActionUsageDeSerializer.cs index e9cecde9..7cacb13b 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PerformActionUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PerformActionUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class PerformActionUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IPerformActionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IPerformActionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("PerformActionUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IPerformActionUsage DeSerialize(JsonElement jsonElement, Seriali } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.PerformActionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actionDefinition"u8, out var actionDefinitionProperty)) { foreach (var arrayItem in actionDefinitionProperty.EnumerateArray()) @@ -2181,8 +2211,278 @@ internal static IPerformActionUsage DeSerialize(JsonElement jsonElement, Seriali logger.LogDebug("the variantMembership Json property was not found in the PerformActionUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.PerformActionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 PerformActionUsage: { 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 PerformActionUsage: { 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 PerformActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the PerformActionUsage: { 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 PerformActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the PerformActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the PerformActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the PerformActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the PerformActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the PerformActionUsage: { 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 PerformActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the PerformActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the PerformActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the PerformActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the PerformActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the PerformActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the PerformActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the PerformActionUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the PerformActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the PerformActionUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PortConjugationDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PortConjugationDeSerializer.cs index 475f7fc6..bdc76f5e 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PortConjugationDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PortConjugationDeSerializer.cs @@ -49,13 +49,16 @@ internal static class PortConjugationDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IPortConjugation DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IPortConjugation DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("PortConjugationDeSerializer"); @@ -85,6 +88,33 @@ internal static IPortConjugation DeSerialize(JsonElement jsonElement, Serializat } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Ports.PortConjugation dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -532,8 +562,234 @@ internal static IPortConjugation DeSerialize(JsonElement jsonElement, Serializat logger.LogDebug("the textualRepresentation Json property was not found in the PortConjugation: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Ports.PortConjugation dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 PortConjugation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("conjugatedType"u8, out var conjugatedTypeProperty)) + { + if (conjugatedTypeProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.ConjugatedType = Guid.Empty; + logger.LogDebug($"the PortConjugation.ConjugatedType property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (conjugatedTypeProperty.TryGetProperty("@id"u8, out var conjugatedTypeExternalIdProperty)) + { + var propertyValue = conjugatedTypeExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.ConjugatedType = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the conjugatedType Json property was not found in the PortConjugation: { 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 PortConjugation: { 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 PortConjugation: { 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 PortConjugation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the PortConjugation: { 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 PortConjugation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("originalPortDefinition"u8, out var originalPortDefinitionProperty)) + { + if (originalPortDefinitionProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OriginalPortDefinition = Guid.Empty; + logger.LogDebug($"the PortConjugation.OriginalPortDefinition property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (originalPortDefinitionProperty.TryGetProperty("@id"u8, out var originalPortDefinitionExternalIdProperty)) + { + var propertyValue = originalPortDefinitionExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OriginalPortDefinition = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the originalPortDefinition Json property was not found in the PortConjugation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the PortConjugation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the PortConjugation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the PortConjugation: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the PortConjugation: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PortDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PortDefinitionDeSerializer.cs index 5014577f..f135d43f 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PortDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PortDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class PortDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IPortDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IPortDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("PortDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IPortDefinition DeSerialize(JsonElement jsonElement, Serializati } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Ports.PortDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1653,8 +1683,176 @@ internal static IPortDefinition DeSerialize(JsonElement jsonElement, Serializati logger.LogDebug("the variantMembership Json property was not found in the PortDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Ports.PortDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 PortDefinition: { 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 PortDefinition: { 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 PortDefinition: { 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 PortDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the PortDefinition: { 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 PortDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the PortDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the PortDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the PortDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the PortDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the PortDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PortUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PortUsageDeSerializer.cs index c5a10e72..c567c407 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PortUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PortUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class PortUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IPortUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IPortUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("PortUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IPortUsage DeSerialize(JsonElement jsonElement, SerializationMod } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Ports.PortUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2156,8 +2186,278 @@ internal static IPortUsage DeSerialize(JsonElement jsonElement, SerializationMod logger.LogDebug("the variantMembership Json property was not found in the PortUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Ports.PortUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 PortUsage: { 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 PortUsage: { 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 PortUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the PortUsage: { 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 PortUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the PortUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the PortUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the PortUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the PortUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the PortUsage: { 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 PortUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the PortUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the PortUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the PortUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the PortUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the PortUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the PortUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the PortUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the PortUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the PortUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PredicateDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PredicateDeSerializer.cs index 6b7a37b2..71c46e1f 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PredicateDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/PredicateDeSerializer.cs @@ -49,13 +49,16 @@ internal static class PredicateDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IPredicate DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IPredicate DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("PredicateDeSerializer"); @@ -85,6 +88,33 @@ internal static IPredicate DeSerialize(JsonElement jsonElement, SerializationMod } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Functions.Predicate dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1062,8 +1092,152 @@ internal static IPredicate DeSerialize(JsonElement jsonElement, SerializationMod logger.LogDebug("the unioningType Json property was not found in the Predicate: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Functions.Predicate dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Predicate: { 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 Predicate: { 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 Predicate: { 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 Predicate: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Predicate: { 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 Predicate: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Predicate: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Predicate: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Predicate: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RedefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RedefinitionDeSerializer.cs index 22e070e6..5224a722 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RedefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RedefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class RedefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IRedefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IRedefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("RedefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IRedefinition DeSerialize(JsonElement jsonElement, Serialization } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.Redefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -531,8 +561,234 @@ internal static IRedefinition DeSerialize(JsonElement jsonElement, Serialization logger.LogDebug("the textualRepresentation Json property was not found in the Redefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.Redefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Redefinition: { 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 Redefinition: { 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 Redefinition: { 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 Redefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Redefinition: { 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 Redefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Redefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Redefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Redefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Redefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("redefinedFeature"u8, out var redefinedFeatureProperty)) + { + if (redefinedFeatureProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.RedefinedFeature = Guid.Empty; + logger.LogDebug($"the Redefinition.RedefinedFeature property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (redefinedFeatureProperty.TryGetProperty("@id"u8, out var redefinedFeatureExternalIdProperty)) + { + var propertyValue = redefinedFeatureExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.RedefinedFeature = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the redefinedFeature Json property was not found in the Redefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("redefiningFeature"u8, out var redefiningFeatureProperty)) + { + if (redefiningFeatureProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.RedefiningFeature = Guid.Empty; + logger.LogDebug($"the Redefinition.RedefiningFeature property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (redefiningFeatureProperty.TryGetProperty("@id"u8, out var redefiningFeatureExternalIdProperty)) + { + var propertyValue = redefiningFeatureExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.RedefiningFeature = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the redefiningFeature Json property was not found in the Redefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ReferenceSubsettingDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ReferenceSubsettingDeSerializer.cs index 270fd317..dea185e0 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ReferenceSubsettingDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ReferenceSubsettingDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ReferenceSubsettingDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IReferenceSubsetting DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IReferenceSubsetting DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ReferenceSubsettingDeSerializer"); @@ -85,6 +88,33 @@ internal static IReferenceSubsetting DeSerialize(JsonElement jsonElement, Serial } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.ReferenceSubsetting dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -507,8 +537,209 @@ internal static IReferenceSubsetting DeSerialize(JsonElement jsonElement, Serial logger.LogDebug("the textualRepresentation Json property was not found in the ReferenceSubsetting: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.ReferenceSubsetting dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ReferenceSubsetting: { 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 ReferenceSubsetting: { 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 ReferenceSubsetting: { 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 ReferenceSubsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the ReferenceSubsetting: { 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 ReferenceSubsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the ReferenceSubsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ReferenceSubsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the ReferenceSubsetting: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ReferenceSubsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("referencedFeature"u8, out var referencedFeatureProperty)) + { + if (referencedFeatureProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.ReferencedFeature = Guid.Empty; + logger.LogDebug($"the ReferenceSubsetting.ReferencedFeature property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (referencedFeatureProperty.TryGetProperty("@id"u8, out var referencedFeatureExternalIdProperty)) + { + var propertyValue = referencedFeatureExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.ReferencedFeature = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the referencedFeature Json property was not found in the ReferenceSubsetting: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ReferenceUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ReferenceUsageDeSerializer.cs index 404bbd2c..4f787155 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ReferenceUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ReferenceUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ReferenceUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IReferenceUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IReferenceUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ReferenceUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IReferenceUsage DeSerialize(JsonElement jsonElement, Serializati } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.DefinitionAndUsage.ReferenceUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2111,8 +2141,257 @@ internal static IReferenceUsage DeSerialize(JsonElement jsonElement, Serializati logger.LogDebug("the variantMembership Json property was not found in the ReferenceUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.DefinitionAndUsage.ReferenceUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ReferenceUsage: { 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 ReferenceUsage: { 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 ReferenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the ReferenceUsage: { 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 ReferenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ReferenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the ReferenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the ReferenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the ReferenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the ReferenceUsage: { 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 ReferenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the ReferenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the ReferenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ReferenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the ReferenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the ReferenceUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ReferenceUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ReferenceUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RenderingDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RenderingDefinitionDeSerializer.cs index 4a03cd4f..977e7875 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RenderingDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RenderingDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class RenderingDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IRenderingDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IRenderingDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("RenderingDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IRenderingDefinition DeSerialize(JsonElement jsonElement, Serial } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Views.RenderingDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1649,8 +1679,176 @@ internal static IRenderingDefinition DeSerialize(JsonElement jsonElement, Serial logger.LogDebug("the variantMembership Json property was not found in the RenderingDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Views.RenderingDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 RenderingDefinition: { 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 RenderingDefinition: { 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 RenderingDefinition: { 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 RenderingDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the RenderingDefinition: { 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 RenderingDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the RenderingDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the RenderingDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the RenderingDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the RenderingDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the RenderingDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RenderingUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RenderingUsageDeSerializer.cs index 7ab5accd..1659031b 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RenderingUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RenderingUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class RenderingUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IRenderingUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IRenderingUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("RenderingUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IRenderingUsage DeSerialize(JsonElement jsonElement, Serializati } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Views.RenderingUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2200,8 +2230,278 @@ internal static IRenderingUsage DeSerialize(JsonElement jsonElement, Serializati logger.LogDebug("the variantMembership Json property was not found in the RenderingUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Views.RenderingUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 RenderingUsage: { 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 RenderingUsage: { 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 RenderingUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the RenderingUsage: { 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 RenderingUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the RenderingUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the RenderingUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the RenderingUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the RenderingUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the RenderingUsage: { 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 RenderingUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the RenderingUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the RenderingUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the RenderingUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the RenderingUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the RenderingUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the RenderingUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the RenderingUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the RenderingUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the RenderingUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RequirementConstraintMembershipDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RequirementConstraintMembershipDeSerializer.cs index 5d3811ca..0543abfc 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RequirementConstraintMembershipDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RequirementConstraintMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class RequirementConstraintMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IRequirementConstraintMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IRequirementConstraintMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("RequirementConstraintMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IRequirementConstraintMembership DeSerialize(JsonElement jsonEle } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.RequirementConstraintMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -582,8 +612,202 @@ internal static IRequirementConstraintMembership DeSerialize(JsonElement jsonEle logger.LogDebug("the visibility Json property was not found in the RequirementConstraintMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.RequirementConstraintMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 RequirementConstraintMembership: { 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 RequirementConstraintMembership: { 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 RequirementConstraintMembership: { 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 RequirementConstraintMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the RequirementConstraintMembership: { 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 RequirementConstraintMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("kind"u8, out var kindProperty)) + { + dtoInstance.Kind = RequirementConstraintKindDeSerializer.Deserialize(kindProperty.GetString()); + } + else + { + logger.LogDebug("the kind Json property was not found in the RequirementConstraintMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the RequirementConstraintMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the RequirementConstraintMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the RequirementConstraintMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the RequirementConstraintMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the RequirementConstraintMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RequirementDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RequirementDefinitionDeSerializer.cs index c6770de7..e201587d 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RequirementDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RequirementDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class RequirementDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IRequirementDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IRequirementDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("RequirementDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IRequirementDefinition DeSerialize(JsonElement jsonElement, Seri } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.RequirementDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actorParameter"u8, out var actorParameterProperty)) { foreach (var arrayItem in actorParameterProperty.EnumerateArray()) @@ -1848,8 +1878,176 @@ internal static IRequirementDefinition DeSerialize(JsonElement jsonElement, Seri logger.LogDebug("the variantMembership Json property was not found in the RequirementDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.RequirementDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 RequirementDefinition: { 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 RequirementDefinition: { 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 RequirementDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the RequirementDefinition: { 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 RequirementDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the RequirementDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the RequirementDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the RequirementDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the RequirementDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the RequirementDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("reqId"u8, out var reqIdProperty)) + { + dtoInstance.ReqId = reqIdProperty.GetString(); + } + else + { + logger.LogDebug("the reqId Json property was not found in the RequirementDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RequirementUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RequirementUsageDeSerializer.cs index f5bfccd7..4e47eba9 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RequirementUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RequirementUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class RequirementUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IRequirementUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IRequirementUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("RequirementUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IRequirementUsage DeSerialize(JsonElement jsonElement, Serializa } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.RequirementUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actorParameter"u8, out var actorParameterProperty)) { foreach (var arrayItem in actorParameterProperty.EnumerateArray()) @@ -2359,8 +2389,278 @@ internal static IRequirementUsage DeSerialize(JsonElement jsonElement, Serializa logger.LogDebug("the variantMembership Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.RequirementUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 RequirementUsage: { 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 RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the RequirementUsage: { 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 RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the RequirementUsage: { 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 RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the RequirementUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("reqId"u8, out var reqIdProperty)) + { + dtoInstance.ReqId = reqIdProperty.GetString(); + } + else + { + logger.LogDebug("the reqId Json property was not found in the RequirementUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RequirementVerificationMembershipDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RequirementVerificationMembershipDeSerializer.cs index 1f479ae4..3d1d083c 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RequirementVerificationMembershipDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/RequirementVerificationMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class RequirementVerificationMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IRequirementVerificationMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IRequirementVerificationMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("RequirementVerificationMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IRequirementVerificationMembership DeSerialize(JsonElement jsonE } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.VerificationCases.RequirementVerificationMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -582,8 +612,202 @@ internal static IRequirementVerificationMembership DeSerialize(JsonElement jsonE logger.LogDebug("the visibility Json property was not found in the RequirementVerificationMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.VerificationCases.RequirementVerificationMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 RequirementVerificationMembership: { 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 RequirementVerificationMembership: { 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 RequirementVerificationMembership: { 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 RequirementVerificationMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the RequirementVerificationMembership: { 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 RequirementVerificationMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("kind"u8, out var kindProperty)) + { + dtoInstance.Kind = RequirementConstraintKindDeSerializer.Deserialize(kindProperty.GetString()); + } + else + { + logger.LogDebug("the kind Json property was not found in the RequirementVerificationMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the RequirementVerificationMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the RequirementVerificationMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the RequirementVerificationMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the RequirementVerificationMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the RequirementVerificationMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ResultExpressionMembershipDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ResultExpressionMembershipDeSerializer.cs index 5a8b579a..a4ce9528 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ResultExpressionMembershipDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ResultExpressionMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ResultExpressionMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IResultExpressionMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IResultExpressionMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ResultExpressionMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IResultExpressionMembership DeSerialize(JsonElement jsonElement, } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Functions.ResultExpressionMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -548,8 +578,193 @@ internal static IResultExpressionMembership DeSerialize(JsonElement jsonElement, logger.LogDebug("the visibility Json property was not found in the ResultExpressionMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Functions.ResultExpressionMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ResultExpressionMembership: { 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 ResultExpressionMembership: { 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 ResultExpressionMembership: { 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 ResultExpressionMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the ResultExpressionMembership: { 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 ResultExpressionMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the ResultExpressionMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ResultExpressionMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the ResultExpressionMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ResultExpressionMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the ResultExpressionMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ReturnParameterMembershipDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ReturnParameterMembershipDeSerializer.cs index 684a3382..8dd56fae 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ReturnParameterMembershipDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ReturnParameterMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ReturnParameterMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IReturnParameterMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IReturnParameterMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ReturnParameterMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IReturnParameterMembership DeSerialize(JsonElement jsonElement, } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Functions.ReturnParameterMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -548,8 +578,193 @@ internal static IReturnParameterMembership DeSerialize(JsonElement jsonElement, logger.LogDebug("the visibility Json property was not found in the ReturnParameterMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Functions.ReturnParameterMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ReturnParameterMembership: { 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 ReturnParameterMembership: { 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 ReturnParameterMembership: { 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 ReturnParameterMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the ReturnParameterMembership: { 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 ReturnParameterMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the ReturnParameterMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ReturnParameterMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the ReturnParameterMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ReturnParameterMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the ReturnParameterMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SatisfyRequirementUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SatisfyRequirementUsageDeSerializer.cs index ecfa3fd1..f255d7d5 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SatisfyRequirementUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SatisfyRequirementUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class SatisfyRequirementUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ISatisfyRequirementUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ISatisfyRequirementUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("SatisfyRequirementUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static ISatisfyRequirementUsage DeSerialize(JsonElement jsonElement, Se } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.SatisfyRequirementUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actorParameter"u8, out var actorParameterProperty)) { foreach (var arrayItem in actorParameterProperty.EnumerateArray()) @@ -2421,8 +2451,290 @@ internal static ISatisfyRequirementUsage DeSerialize(JsonElement jsonElement, Se logger.LogDebug("the variantMembership Json property was not found in the SatisfyRequirementUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.SatisfyRequirementUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 SatisfyRequirementUsage: { 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 SatisfyRequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the SatisfyRequirementUsage: { 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 SatisfyRequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the SatisfyRequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the SatisfyRequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the SatisfyRequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the SatisfyRequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the SatisfyRequirementUsage: { 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 SatisfyRequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the SatisfyRequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isNegated"u8, out var isNegatedProperty)) + { + if (isNegatedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsNegated = isNegatedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isNegated Json property was not found in the SatisfyRequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the SatisfyRequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the SatisfyRequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the SatisfyRequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the SatisfyRequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the SatisfyRequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the SatisfyRequirementUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the SatisfyRequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the SatisfyRequirementUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("reqId"u8, out var reqIdProperty)) + { + dtoInstance.ReqId = reqIdProperty.GetString(); + } + else + { + logger.LogDebug("the reqId Json property was not found in the SatisfyRequirementUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SelectExpressionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SelectExpressionDeSerializer.cs index e45512bf..464c5e87 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SelectExpressionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SelectExpressionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class SelectExpressionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ISelectExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ISelectExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("SelectExpressionDeSerializer"); @@ -85,6 +88,33 @@ internal static ISelectExpression DeSerialize(JsonElement jsonElement, Serializa } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.SelectExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1539,8 +1569,271 @@ internal static ISelectExpression DeSerialize(JsonElement jsonElement, Serializa logger.LogDebug("the unioningType Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Expressions.SelectExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 SelectExpression: { 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 SelectExpression: { 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 SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the SelectExpression: { 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 SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the SelectExpression: { 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 SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("operator"u8, out var operatorProperty)) + { + var propertyValue = operatorProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Operator = propertyValue; + } + } + else + { + logger.LogDebug("the operator Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the SelectExpression: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the SelectExpression: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SendActionUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SendActionUsageDeSerializer.cs index 6198c2cf..37f87990 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SendActionUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SendActionUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class SendActionUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ISendActionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ISendActionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("SendActionUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static ISendActionUsage DeSerialize(JsonElement jsonElement, Serializat } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.SendActionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actionDefinition"u8, out var actionDefinitionProperty)) { foreach (var arrayItem in actionDefinitionProperty.EnumerateArray()) @@ -2229,8 +2259,278 @@ internal static ISendActionUsage DeSerialize(JsonElement jsonElement, Serializat logger.LogDebug("the variantMembership Json property was not found in the SendActionUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.SendActionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 SendActionUsage: { 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 SendActionUsage: { 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 SendActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the SendActionUsage: { 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 SendActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the SendActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the SendActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the SendActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the SendActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the SendActionUsage: { 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 SendActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the SendActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the SendActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the SendActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the SendActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the SendActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the SendActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the SendActionUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the SendActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the SendActionUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SpecializationDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SpecializationDeSerializer.cs index 0ac1e8b7..40b68cec 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SpecializationDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SpecializationDeSerializer.cs @@ -49,13 +49,16 @@ internal static class SpecializationDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ISpecialization DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ISpecialization DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("SpecializationDeSerializer"); @@ -85,6 +88,33 @@ internal static ISpecialization DeSerialize(JsonElement jsonElement, Serializati } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Types.Specialization dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -531,8 +561,234 @@ internal static ISpecialization DeSerialize(JsonElement jsonElement, Serializati logger.LogDebug("the textualRepresentation Json property was not found in the Specialization: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Types.Specialization dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Specialization: { 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 Specialization: { 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 Specialization: { 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 Specialization: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("general"u8, out var generalProperty)) + { + if (generalProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.General = Guid.Empty; + logger.LogDebug($"the Specialization.General property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (generalProperty.TryGetProperty("@id"u8, out var generalExternalIdProperty)) + { + var propertyValue = generalExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.General = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the general Json property was not found in the Specialization: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Specialization: { 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 Specialization: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Specialization: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Specialization: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Specialization: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Specialization: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("specific"u8, out var specificProperty)) + { + if (specificProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.Specific = Guid.Empty; + logger.LogDebug($"the Specialization.Specific property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (specificProperty.TryGetProperty("@id"u8, out var specificExternalIdProperty)) + { + var propertyValue = specificExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Specific = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the specific Json property was not found in the Specialization: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StakeholderMembershipDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StakeholderMembershipDeSerializer.cs index 4287c5b3..6c93b3d3 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StakeholderMembershipDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StakeholderMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class StakeholderMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IStakeholderMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IStakeholderMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("StakeholderMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IStakeholderMembership DeSerialize(JsonElement jsonElement, Seri } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.StakeholderMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -548,8 +578,193 @@ internal static IStakeholderMembership DeSerialize(JsonElement jsonElement, Seri logger.LogDebug("the visibility Json property was not found in the StakeholderMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.StakeholderMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 StakeholderMembership: { 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 StakeholderMembership: { 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 StakeholderMembership: { 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 StakeholderMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the StakeholderMembership: { 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 StakeholderMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the StakeholderMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the StakeholderMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the StakeholderMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the StakeholderMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the StakeholderMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StateDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StateDefinitionDeSerializer.cs index 4a7315db..35e4bacd 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StateDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StateDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class StateDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IStateDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IStateDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("StateDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IStateDefinition DeSerialize(JsonElement jsonElement, Serializat } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.States.StateDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("action"u8, out var actionProperty)) { foreach (var arrayItem in actionProperty.EnumerateArray()) @@ -1773,8 +1803,188 @@ internal static IStateDefinition DeSerialize(JsonElement jsonElement, Serializat logger.LogDebug("the variantMembership Json property was not found in the StateDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.States.StateDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 StateDefinition: { 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 StateDefinition: { 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 StateDefinition: { 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 StateDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the StateDefinition: { 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 StateDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the StateDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isParallel"u8, out var isParallelProperty)) + { + if (isParallelProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsParallel = isParallelProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isParallel Json property was not found in the StateDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the StateDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the StateDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the StateDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the StateDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StateSubactionMembershipDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StateSubactionMembershipDeSerializer.cs index ee0dda47..a14d3f73 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StateSubactionMembershipDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StateSubactionMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class StateSubactionMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IStateSubactionMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IStateSubactionMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("StateSubactionMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IStateSubactionMembership DeSerialize(JsonElement jsonElement, S } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.States.StateSubactionMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("action"u8, out var actionProperty)) { if (actionProperty.ValueKind == JsonValueKind.Null) @@ -557,8 +587,202 @@ internal static IStateSubactionMembership DeSerialize(JsonElement jsonElement, S logger.LogDebug("the visibility Json property was not found in the StateSubactionMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.States.StateSubactionMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 StateSubactionMembership: { 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 StateSubactionMembership: { 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 StateSubactionMembership: { 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 StateSubactionMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the StateSubactionMembership: { 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 StateSubactionMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("kind"u8, out var kindProperty)) + { + dtoInstance.Kind = StateSubactionKindDeSerializer.Deserialize(kindProperty.GetString()); + } + else + { + logger.LogDebug("the kind Json property was not found in the StateSubactionMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the StateSubactionMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the StateSubactionMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the StateSubactionMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the StateSubactionMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the StateSubactionMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StateUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StateUsageDeSerializer.cs index 1be5e6c5..27a375f9 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StateUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StateUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class StateUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IStateUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IStateUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("StateUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IStateUsage DeSerialize(JsonElement jsonElement, SerializationMo } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.States.StateUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2240,8 +2270,290 @@ internal static IStateUsage DeSerialize(JsonElement jsonElement, SerializationMo logger.LogDebug("the variantMembership Json property was not found in the StateUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.States.StateUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 StateUsage: { 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 StateUsage: { 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 StateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the StateUsage: { 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 StateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the StateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the StateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the StateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the StateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the StateUsage: { 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 StateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the StateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the StateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isParallel"u8, out var isParallelProperty)) + { + if (isParallelProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsParallel = isParallelProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isParallel Json property was not found in the StateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the StateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the StateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the StateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the StateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the StateUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the StateUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the StateUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StepDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StepDeSerializer.cs index 5dc28564..d5d763e6 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StepDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StepDeSerializer.cs @@ -49,13 +49,16 @@ internal static class StepDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IStep DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IStep DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("StepDeSerializer"); @@ -85,6 +88,33 @@ internal static IStep DeSerialize(JsonElement jsonElement, SerializationModeKind } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Behaviors.Step dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1439,8 +1469,257 @@ internal static IStep DeSerialize(JsonElement jsonElement, SerializationModeKind logger.LogDebug("the unioningType Json property was not found in the Step: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Behaviors.Step dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Step: { 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 Step: { 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 Step: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the Step: { 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 Step: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Step: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the Step: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the Step: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the Step: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the Step: { 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 Step: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the Step: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the Step: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Step: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the Step: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the Step: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Step: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Step: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StructureDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StructureDeSerializer.cs index 9a11a12d..c9cda4a5 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StructureDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/StructureDeSerializer.cs @@ -49,13 +49,16 @@ internal static class StructureDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IStructure DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IStructure DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("StructureDeSerializer"); @@ -85,6 +88,33 @@ internal static IStructure DeSerialize(JsonElement jsonElement, SerializationMod } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Structures.Structure dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -985,8 +1015,152 @@ internal static IStructure DeSerialize(JsonElement jsonElement, SerializationMod logger.LogDebug("the unioningType Json property was not found in the Structure: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Structures.Structure dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Structure: { 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 Structure: { 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 Structure: { 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 Structure: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Structure: { 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 Structure: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Structure: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Structure: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Structure: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SubclassificationDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SubclassificationDeSerializer.cs index 76f5ed37..153881d1 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SubclassificationDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SubclassificationDeSerializer.cs @@ -49,13 +49,16 @@ internal static class SubclassificationDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ISubclassification DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ISubclassification DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("SubclassificationDeSerializer"); @@ -85,6 +88,33 @@ internal static ISubclassification DeSerialize(JsonElement jsonElement, Serializ } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Classifiers.Subclassification dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -531,8 +561,234 @@ internal static ISubclassification DeSerialize(JsonElement jsonElement, Serializ logger.LogDebug("the textualRepresentation Json property was not found in the Subclassification: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Classifiers.Subclassification dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Subclassification: { 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 Subclassification: { 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 Subclassification: { 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 Subclassification: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Subclassification: { 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 Subclassification: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Subclassification: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Subclassification: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Subclassification: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Subclassification: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("subclassifier"u8, out var subclassifierProperty)) + { + if (subclassifierProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.Subclassifier = Guid.Empty; + logger.LogDebug($"the Subclassification.Subclassifier property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (subclassifierProperty.TryGetProperty("@id"u8, out var subclassifierExternalIdProperty)) + { + var propertyValue = subclassifierExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Subclassifier = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the subclassifier Json property was not found in the Subclassification: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("superclassifier"u8, out var superclassifierProperty)) + { + if (superclassifierProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.Superclassifier = Guid.Empty; + logger.LogDebug($"the Subclassification.Superclassifier property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (superclassifierProperty.TryGetProperty("@id"u8, out var superclassifierExternalIdProperty)) + { + var propertyValue = superclassifierExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Superclassifier = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the superclassifier Json property was not found in the Subclassification: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SubjectMembershipDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SubjectMembershipDeSerializer.cs index d4717f93..0cd8e340 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SubjectMembershipDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SubjectMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class SubjectMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ISubjectMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ISubjectMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("SubjectMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static ISubjectMembership DeSerialize(JsonElement jsonElement, Serializ } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.SubjectMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -548,8 +578,193 @@ internal static ISubjectMembership DeSerialize(JsonElement jsonElement, Serializ logger.LogDebug("the visibility Json property was not found in the SubjectMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Requirements.SubjectMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 SubjectMembership: { 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 SubjectMembership: { 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 SubjectMembership: { 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 SubjectMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the SubjectMembership: { 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 SubjectMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the SubjectMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the SubjectMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the SubjectMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the SubjectMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the SubjectMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SubsettingDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SubsettingDeSerializer.cs index 813d9ed8..33a4877f 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SubsettingDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SubsettingDeSerializer.cs @@ -49,13 +49,16 @@ internal static class SubsettingDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ISubsetting DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ISubsetting DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("SubsettingDeSerializer"); @@ -85,6 +88,33 @@ internal static ISubsetting DeSerialize(JsonElement jsonElement, SerializationMo } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.Subsetting dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -531,8 +561,234 @@ internal static ISubsetting DeSerialize(JsonElement jsonElement, SerializationMo logger.LogDebug("the textualRepresentation Json property was not found in the Subsetting: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.Subsetting dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Subsetting: { 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 Subsetting: { 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 Subsetting: { 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 Subsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Subsetting: { 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 Subsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Subsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Subsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Subsetting: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Subsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("subsettedFeature"u8, out var subsettedFeatureProperty)) + { + if (subsettedFeatureProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.SubsettedFeature = Guid.Empty; + logger.LogDebug($"the Subsetting.SubsettedFeature property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (subsettedFeatureProperty.TryGetProperty("@id"u8, out var subsettedFeatureExternalIdProperty)) + { + var propertyValue = subsettedFeatureExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.SubsettedFeature = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the subsettedFeature Json property was not found in the Subsetting: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("subsettingFeature"u8, out var subsettingFeatureProperty)) + { + if (subsettingFeatureProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.SubsettingFeature = Guid.Empty; + logger.LogDebug($"the Subsetting.SubsettingFeature property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (subsettingFeatureProperty.TryGetProperty("@id"u8, out var subsettingFeatureExternalIdProperty)) + { + var propertyValue = subsettingFeatureExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.SubsettingFeature = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the subsettingFeature Json property was not found in the Subsetting: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SuccessionAsUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SuccessionAsUsageDeSerializer.cs index 6722dc40..c97e9c45 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SuccessionAsUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SuccessionAsUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class SuccessionAsUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ISuccessionAsUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ISuccessionAsUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("SuccessionAsUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static ISuccessionAsUsage DeSerialize(JsonElement jsonElement, Serializ } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Connections.SuccessionAsUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2275,8 +2305,313 @@ internal static ISuccessionAsUsage DeSerialize(JsonElement jsonElement, Serializ logger.LogDebug("the variantMembership Json property was not found in the SuccessionAsUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Connections.SuccessionAsUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 SuccessionAsUsage: { 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 SuccessionAsUsage: { 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 SuccessionAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the SuccessionAsUsage: { 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 SuccessionAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the SuccessionAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the SuccessionAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the SuccessionAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the SuccessionAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the SuccessionAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the SuccessionAsUsage: { 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 SuccessionAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the SuccessionAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the SuccessionAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the SuccessionAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the SuccessionAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the SuccessionAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the SuccessionAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the SuccessionAsUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the SuccessionAsUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the SuccessionAsUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SuccessionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SuccessionDeSerializer.cs index 058b7899..e84da98d 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SuccessionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SuccessionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class SuccessionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ISuccession DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ISuccession DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("SuccessionDeSerializer"); @@ -85,6 +88,33 @@ internal static ISuccession DeSerialize(JsonElement jsonElement, SerializationMo } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Connectors.Succession dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1563,8 +1593,313 @@ internal static ISuccession DeSerialize(JsonElement jsonElement, SerializationMo logger.LogDebug("the unioningType Json property was not found in the Succession: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Connectors.Succession dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Succession: { 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 Succession: { 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 Succession: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the Succession: { 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 Succession: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Succession: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the Succession: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the Succession: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the Succession: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the Succession: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Succession: { 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 Succession: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the Succession: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the Succession: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Succession: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the Succession: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the Succession: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Succession: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Succession: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Succession: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Succession: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SuccessionFlowDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SuccessionFlowDeSerializer.cs index 1a275b78..90b24560 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SuccessionFlowDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SuccessionFlowDeSerializer.cs @@ -49,13 +49,16 @@ internal static class SuccessionFlowDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ISuccessionFlow DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ISuccessionFlow DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("SuccessionFlowDeSerializer"); @@ -85,6 +88,33 @@ internal static ISuccessionFlow DeSerialize(JsonElement jsonElement, Serializati } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Interactions.SuccessionFlow dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1675,8 +1705,313 @@ internal static ISuccessionFlow DeSerialize(JsonElement jsonElement, Serializati logger.LogDebug("the unioningType Json property was not found in the SuccessionFlow: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Kernel.Interactions.SuccessionFlow dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 SuccessionFlow: { 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 SuccessionFlow: { 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 SuccessionFlow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the SuccessionFlow: { 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 SuccessionFlow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the SuccessionFlow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the SuccessionFlow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the SuccessionFlow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the SuccessionFlow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the SuccessionFlow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the SuccessionFlow: { 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 SuccessionFlow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the SuccessionFlow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the SuccessionFlow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the SuccessionFlow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the SuccessionFlow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the SuccessionFlow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the SuccessionFlow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the SuccessionFlow: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the SuccessionFlow: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the SuccessionFlow: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SuccessionFlowUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SuccessionFlowUsageDeSerializer.cs index ee81280b..6048c4b9 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SuccessionFlowUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/SuccessionFlowUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class SuccessionFlowUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ISuccessionFlowUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ISuccessionFlowUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("SuccessionFlowUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static ISuccessionFlowUsage DeSerialize(JsonElement jsonElement, Serial } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Flows.SuccessionFlowUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2412,8 +2442,334 @@ internal static ISuccessionFlowUsage DeSerialize(JsonElement jsonElement, Serial logger.LogDebug("the variantMembership Json property was not found in the SuccessionFlowUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Flows.SuccessionFlowUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 SuccessionFlowUsage: { 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 SuccessionFlowUsage: { 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 SuccessionFlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the SuccessionFlowUsage: { 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 SuccessionFlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the SuccessionFlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the SuccessionFlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the SuccessionFlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the SuccessionFlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the SuccessionFlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the SuccessionFlowUsage: { 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 SuccessionFlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the SuccessionFlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the SuccessionFlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the SuccessionFlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the SuccessionFlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the SuccessionFlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the SuccessionFlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the SuccessionFlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the SuccessionFlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the SuccessionFlowUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the SuccessionFlowUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the SuccessionFlowUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TerminateActionUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TerminateActionUsageDeSerializer.cs index 06fde9ed..8786109c 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TerminateActionUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TerminateActionUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class TerminateActionUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ITerminateActionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ITerminateActionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("TerminateActionUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static ITerminateActionUsage DeSerialize(JsonElement jsonElement, Seria } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.TerminateActionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actionDefinition"u8, out var actionDefinitionProperty)) { foreach (var arrayItem in actionDefinitionProperty.EnumerateArray()) @@ -2180,8 +2210,278 @@ internal static ITerminateActionUsage DeSerialize(JsonElement jsonElement, Seria logger.LogDebug("the variantMembership Json property was not found in the TerminateActionUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.TerminateActionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 TerminateActionUsage: { 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 TerminateActionUsage: { 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 TerminateActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the TerminateActionUsage: { 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 TerminateActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the TerminateActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the TerminateActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the TerminateActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the TerminateActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the TerminateActionUsage: { 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 TerminateActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the TerminateActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the TerminateActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the TerminateActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the TerminateActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the TerminateActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the TerminateActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the TerminateActionUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the TerminateActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the TerminateActionUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TextualRepresentationDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TextualRepresentationDeSerializer.cs index 1925ce76..9f36642f 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TextualRepresentationDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TextualRepresentationDeSerializer.cs @@ -49,13 +49,16 @@ internal static class TextualRepresentationDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ITextualRepresentation DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ITextualRepresentation DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("TextualRepresentationDeSerializer"); @@ -85,6 +88,33 @@ internal static ITextualRepresentation DeSerialize(JsonElement jsonElement, Seri } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Root.Annotations.TextualRepresentation dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -498,8 +528,156 @@ internal static ITextualRepresentation DeSerialize(JsonElement jsonElement, Seri logger.LogDebug("the textualRepresentation Json property was not found in the TextualRepresentation: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Root.Annotations.TextualRepresentation dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 TextualRepresentation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("body"u8, out var bodyProperty)) + { + var propertyValue = bodyProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Body = propertyValue; + } + } + else + { + logger.LogDebug("the body Json property was not found in the TextualRepresentation: { 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 TextualRepresentation: { 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 TextualRepresentation: { 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 TextualRepresentation: { 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 TextualRepresentation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("language"u8, out var languageProperty)) + { + var propertyValue = languageProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.Language = propertyValue; + } + } + else + { + logger.LogDebug("the language Json property was not found in the TextualRepresentation: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the TextualRepresentation: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the TextualRepresentation: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TransitionFeatureMembershipDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TransitionFeatureMembershipDeSerializer.cs index 91f13556..0818a752 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TransitionFeatureMembershipDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TransitionFeatureMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class TransitionFeatureMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ITransitionFeatureMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ITransitionFeatureMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("TransitionFeatureMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static ITransitionFeatureMembership DeSerialize(JsonElement jsonElement } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.States.TransitionFeatureMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -557,8 +587,202 @@ internal static ITransitionFeatureMembership DeSerialize(JsonElement jsonElement logger.LogDebug("the visibility Json property was not found in the TransitionFeatureMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.States.TransitionFeatureMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 TransitionFeatureMembership: { 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 TransitionFeatureMembership: { 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 TransitionFeatureMembership: { 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 TransitionFeatureMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the TransitionFeatureMembership: { 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 TransitionFeatureMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("kind"u8, out var kindProperty)) + { + dtoInstance.Kind = TransitionFeatureKindDeSerializer.Deserialize(kindProperty.GetString()); + } + else + { + logger.LogDebug("the kind Json property was not found in the TransitionFeatureMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the TransitionFeatureMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the TransitionFeatureMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the TransitionFeatureMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the TransitionFeatureMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the TransitionFeatureMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TransitionUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TransitionUsageDeSerializer.cs index e945b2d8..54196bed 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TransitionUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TransitionUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class TransitionUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ITransitionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ITransitionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("TransitionUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static ITransitionUsage DeSerialize(JsonElement jsonElement, Serializat } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.States.TransitionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actionDefinition"u8, out var actionDefinitionProperty)) { foreach (var arrayItem in actionDefinitionProperty.EnumerateArray()) @@ -2291,8 +2321,278 @@ internal static ITransitionUsage DeSerialize(JsonElement jsonElement, Serializat logger.LogDebug("the variantMembership Json property was not found in the TransitionUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.States.TransitionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 TransitionUsage: { 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 TransitionUsage: { 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 TransitionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the TransitionUsage: { 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 TransitionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the TransitionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the TransitionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the TransitionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the TransitionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the TransitionUsage: { 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 TransitionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the TransitionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the TransitionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the TransitionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the TransitionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the TransitionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the TransitionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the TransitionUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the TransitionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the TransitionUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TriggerInvocationExpressionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TriggerInvocationExpressionDeSerializer.cs index b2b2f174..3c29e291 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TriggerInvocationExpressionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TriggerInvocationExpressionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class TriggerInvocationExpressionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ITriggerInvocationExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ITriggerInvocationExpression DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("TriggerInvocationExpressionDeSerializer"); @@ -85,6 +88,33 @@ internal static ITriggerInvocationExpression DeSerialize(JsonElement jsonElement } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.TriggerInvocationExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1534,8 +1564,266 @@ internal static ITriggerInvocationExpression DeSerialize(JsonElement jsonElement logger.LogDebug("the unioningType Json property was not found in the TriggerInvocationExpression: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.TriggerInvocationExpression dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 TriggerInvocationExpression: { 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 TriggerInvocationExpression: { 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 TriggerInvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the TriggerInvocationExpression: { 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 TriggerInvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the TriggerInvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the TriggerInvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the TriggerInvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the TriggerInvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the TriggerInvocationExpression: { 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 TriggerInvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the TriggerInvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the TriggerInvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the TriggerInvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the TriggerInvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariable"u8, out var isVariableProperty)) + { + if (isVariableProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariable = isVariableProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariable Json property was not found in the TriggerInvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("kind"u8, out var kindProperty)) + { + dtoInstance.Kind = TriggerKindDeSerializer.Deserialize(kindProperty.GetString()); + } + else + { + logger.LogDebug("the kind Json property was not found in the TriggerInvocationExpression: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the TriggerInvocationExpression: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the TriggerInvocationExpression: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TypeDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TypeDeSerializer.cs index 0b2af049..4f07ef58 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TypeDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TypeDeSerializer.cs @@ -49,13 +49,16 @@ internal static class TypeDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IType DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IType DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("TypeDeSerializer"); @@ -85,6 +88,33 @@ internal static IType DeSerialize(JsonElement jsonElement, SerializationModeKind } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Types.Type dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -965,8 +995,152 @@ internal static IType DeSerialize(JsonElement jsonElement, SerializationModeKind logger.LogDebug("the unioningType Json property was not found in the Type: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Types.Type dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Type: { 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 Type: { 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 Type: { 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 Type: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Type: { 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 Type: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Type: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Type: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Type: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TypeFeaturingDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TypeFeaturingDeSerializer.cs index e30c12df..ab811985 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TypeFeaturingDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/TypeFeaturingDeSerializer.cs @@ -49,13 +49,16 @@ internal static class TypeFeaturingDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static ITypeFeaturing DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static ITypeFeaturing DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("TypeFeaturingDeSerializer"); @@ -85,6 +88,33 @@ internal static ITypeFeaturing DeSerialize(JsonElement jsonElement, Serializatio } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.TypeFeaturing dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -531,8 +561,234 @@ internal static ITypeFeaturing DeSerialize(JsonElement jsonElement, Serializatio logger.LogDebug("the textualRepresentation Json property was not found in the TypeFeaturing: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Features.TypeFeaturing dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 TypeFeaturing: { 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 TypeFeaturing: { 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 TypeFeaturing: { 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 TypeFeaturing: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("featureOfType"u8, out var featureOfTypeProperty)) + { + if (featureOfTypeProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.FeatureOfType = Guid.Empty; + logger.LogDebug($"the TypeFeaturing.FeatureOfType property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (featureOfTypeProperty.TryGetProperty("@id"u8, out var featureOfTypeExternalIdProperty)) + { + var propertyValue = featureOfTypeExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.FeatureOfType = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the featureOfType Json property was not found in the TypeFeaturing: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("featuringType"u8, out var featuringTypeProperty)) + { + if (featuringTypeProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.FeaturingType = Guid.Empty; + logger.LogDebug($"the TypeFeaturing.FeaturingType property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (featuringTypeProperty.TryGetProperty("@id"u8, out var featuringTypeExternalIdProperty)) + { + var propertyValue = featuringTypeExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.FeaturingType = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the featuringType Json property was not found in the TypeFeaturing: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the TypeFeaturing: { 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 TypeFeaturing: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the TypeFeaturing: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the TypeFeaturing: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the TypeFeaturing: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the TypeFeaturing: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/UnioningDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/UnioningDeSerializer.cs index 18ee981b..f772578e 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/UnioningDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/UnioningDeSerializer.cs @@ -49,13 +49,16 @@ internal static class UnioningDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IUnioning DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IUnioning DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("UnioningDeSerializer"); @@ -85,6 +88,33 @@ internal static IUnioning DeSerialize(JsonElement jsonElement, SerializationMode } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Core.Types.Unioning dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -507,8 +537,209 @@ internal static IUnioning DeSerialize(JsonElement jsonElement, SerializationMode logger.LogDebug("the unioningType Json property was not found in the Unioning: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Core.Types.Unioning dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Unioning: { 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 Unioning: { 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 Unioning: { 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 Unioning: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the Unioning: { 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 Unioning: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the Unioning: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Unioning: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the Unioning: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Unioning: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("unioningType"u8, out var unioningTypeProperty)) + { + if (unioningTypeProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.UnioningType = Guid.Empty; + logger.LogDebug($"the Unioning.UnioningType property was not found in the Json. The value is set to Guid.Empty"); + } + else + { + if (unioningTypeProperty.TryGetProperty("@id"u8, out var unioningTypeExternalIdProperty)) + { + var propertyValue = unioningTypeExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.UnioningType = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the unioningType Json property was not found in the Unioning: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/UsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/UsageDeSerializer.cs index 5deaec1c..18a68960 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/UsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/UsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class UsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("UsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IUsage DeSerialize(JsonElement jsonElement, SerializationModeKin } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.DefinitionAndUsage.Usage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2111,8 +2141,257 @@ internal static IUsage DeSerialize(JsonElement jsonElement, SerializationModeKin logger.LogDebug("the variantMembership Json property was not found in the Usage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.DefinitionAndUsage.Usage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 Usage: { 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 Usage: { 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 Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the Usage: { 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 Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the Usage: { 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 Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the Usage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the Usage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the Usage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/UseCaseDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/UseCaseDefinitionDeSerializer.cs index bab006b7..4514ded2 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/UseCaseDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/UseCaseDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class UseCaseDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IUseCaseDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IUseCaseDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("UseCaseDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IUseCaseDefinition DeSerialize(JsonElement jsonElement, Serializ } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.UseCases.UseCaseDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("action"u8, out var actionProperty)) { foreach (var arrayItem in actionProperty.EnumerateArray()) @@ -1835,8 +1865,176 @@ internal static IUseCaseDefinition DeSerialize(JsonElement jsonElement, Serializ logger.LogDebug("the variantMembership Json property was not found in the UseCaseDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.UseCases.UseCaseDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 UseCaseDefinition: { 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 UseCaseDefinition: { 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 UseCaseDefinition: { 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 UseCaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the UseCaseDefinition: { 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 UseCaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the UseCaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the UseCaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the UseCaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the UseCaseDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the UseCaseDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/UseCaseUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/UseCaseUsageDeSerializer.cs index f0bca3b3..2c835d1e 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/UseCaseUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/UseCaseUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class UseCaseUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IUseCaseUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IUseCaseUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("UseCaseUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IUseCaseUsage DeSerialize(JsonElement jsonElement, Serialization } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.UseCases.UseCaseUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actorParameter"u8, out var actorParameterProperty)) { foreach (var arrayItem in actorParameterProperty.EnumerateArray()) @@ -2286,8 +2316,278 @@ internal static IUseCaseUsage DeSerialize(JsonElement jsonElement, Serialization logger.LogDebug("the variantMembership Json property was not found in the UseCaseUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.UseCases.UseCaseUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 UseCaseUsage: { 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 UseCaseUsage: { 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 UseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the UseCaseUsage: { 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 UseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the UseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the UseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the UseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the UseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the UseCaseUsage: { 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 UseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the UseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the UseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the UseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the UseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the UseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the UseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the UseCaseUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the UseCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the UseCaseUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/VariantMembershipDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/VariantMembershipDeSerializer.cs index 0d7119f0..03fa22c2 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/VariantMembershipDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/VariantMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class VariantMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IVariantMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IVariantMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("VariantMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IVariantMembership DeSerialize(JsonElement jsonElement, Serializ } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.DefinitionAndUsage.VariantMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -548,8 +578,193 @@ internal static IVariantMembership DeSerialize(JsonElement jsonElement, Serializ logger.LogDebug("the visibility Json property was not found in the VariantMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.DefinitionAndUsage.VariantMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 VariantMembership: { 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 VariantMembership: { 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 VariantMembership: { 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 VariantMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the VariantMembership: { 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 VariantMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the VariantMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the VariantMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the VariantMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the VariantMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the VariantMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/VerificationCaseDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/VerificationCaseDefinitionDeSerializer.cs index b68a900c..d83e26e6 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/VerificationCaseDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/VerificationCaseDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class VerificationCaseDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IVerificationCaseDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IVerificationCaseDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("VerificationCaseDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IVerificationCaseDefinition DeSerialize(JsonElement jsonElement, } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.VerificationCases.VerificationCaseDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("action"u8, out var actionProperty)) { foreach (var arrayItem in actionProperty.EnumerateArray()) @@ -1835,8 +1865,176 @@ internal static IVerificationCaseDefinition DeSerialize(JsonElement jsonElement, logger.LogDebug("the verifiedRequirement Json property was not found in the VerificationCaseDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.VerificationCases.VerificationCaseDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 VerificationCaseDefinition: { 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 VerificationCaseDefinition: { 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 VerificationCaseDefinition: { 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 VerificationCaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the VerificationCaseDefinition: { 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 VerificationCaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the VerificationCaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the VerificationCaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the VerificationCaseDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the VerificationCaseDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the VerificationCaseDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/VerificationCaseUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/VerificationCaseUsageDeSerializer.cs index 3a0d89f8..6a10f849 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/VerificationCaseUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/VerificationCaseUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class VerificationCaseUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IVerificationCaseUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IVerificationCaseUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("VerificationCaseUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IVerificationCaseUsage DeSerialize(JsonElement jsonElement, Seri } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.VerificationCases.VerificationCaseUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actorParameter"u8, out var actorParameterProperty)) { foreach (var arrayItem in actorParameterProperty.EnumerateArray()) @@ -2310,8 +2340,278 @@ internal static IVerificationCaseUsage DeSerialize(JsonElement jsonElement, Seri logger.LogDebug("the verifiedRequirement Json property was not found in the VerificationCaseUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.VerificationCases.VerificationCaseUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 VerificationCaseUsage: { 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 VerificationCaseUsage: { 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 VerificationCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the VerificationCaseUsage: { 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 VerificationCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the VerificationCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the VerificationCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the VerificationCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the VerificationCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the VerificationCaseUsage: { 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 VerificationCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the VerificationCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the VerificationCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the VerificationCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the VerificationCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the VerificationCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the VerificationCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the VerificationCaseUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the VerificationCaseUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the VerificationCaseUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewDefinitionDeSerializer.cs index 355d1c09..ca7a0282 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ViewDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IViewDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IViewDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ViewDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IViewDefinition DeSerialize(JsonElement jsonElement, Serializati } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Views.ViewDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -1713,8 +1743,176 @@ internal static IViewDefinition DeSerialize(JsonElement jsonElement, Serializati logger.LogDebug("the viewRendering Json property was not found in the ViewDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Views.ViewDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ViewDefinition: { 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 ViewDefinition: { 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 ViewDefinition: { 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 ViewDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ViewDefinition: { 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 ViewDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the ViewDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ViewDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the ViewDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ViewDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ViewDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewRenderingMembershipDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewRenderingMembershipDeSerializer.cs index c29fdb66..9900cbe1 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewRenderingMembershipDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewRenderingMembershipDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ViewRenderingMembershipDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IViewRenderingMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IViewRenderingMembership DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ViewRenderingMembershipDeSerializer"); @@ -85,6 +88,33 @@ internal static IViewRenderingMembership DeSerialize(JsonElement jsonElement, Se } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Views.ViewRenderingMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -573,8 +603,193 @@ internal static IViewRenderingMembership DeSerialize(JsonElement jsonElement, Se logger.LogDebug("the visibility Json property was not found in the ViewRenderingMembership: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Views.ViewRenderingMembership dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ViewRenderingMembership: { 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 ViewRenderingMembership: { 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 ViewRenderingMembership: { 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 ViewRenderingMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isImplied"u8, out var isImpliedProperty)) + { + if (isImpliedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsImplied = isImpliedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isImplied Json property was not found in the ViewRenderingMembership: { 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 ViewRenderingMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelatedElement"u8, out var ownedRelatedElementProperty)) + { + foreach (var arrayItem in ownedRelatedElementProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelatedElementExternalIdProperty)) + { + var propertyValue = ownedRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelatedElement.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelatedElement Json property was not found in the ViewRenderingMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ViewRenderingMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("owningRelatedElement"u8, out var owningRelatedElementProperty)) + { + if (owningRelatedElementProperty.ValueKind == JsonValueKind.Null) + { + dtoInstance.OwningRelatedElement = null; + } + else + { + if (owningRelatedElementProperty.TryGetProperty("@id"u8, out var owningRelatedElementExternalIdProperty)) + { + var propertyValue = owningRelatedElementExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelatedElement = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelatedElement Json property was not found in the ViewRenderingMembership: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ViewRenderingMembership: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("visibility"u8, out var visibilityProperty)) + { + dtoInstance.Visibility = VisibilityKindDeSerializer.Deserialize(visibilityProperty.GetString()); + } + else + { + logger.LogDebug("the visibility Json property was not found in the ViewRenderingMembership: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewUsageDeSerializer.cs index 5e4a2407..e9229580 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ViewUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IViewUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IViewUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ViewUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IViewUsage DeSerialize(JsonElement jsonElement, SerializationMod } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Views.ViewUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("aliasIds"u8, out var aliasIdsProperty)) { foreach (var arrayItem in aliasIdsProperty.EnumerateArray()) @@ -2284,8 +2314,278 @@ internal static IViewUsage DeSerialize(JsonElement jsonElement, SerializationMod logger.LogDebug("the viewRendering Json property was not found in the ViewUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Views.ViewUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ViewUsage: { 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 ViewUsage: { 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 ViewUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the ViewUsage: { 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 ViewUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ViewUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the ViewUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the ViewUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the ViewUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the ViewUsage: { 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 ViewUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the ViewUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the ViewUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the ViewUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ViewUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the ViewUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the ViewUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ViewUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ViewUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the ViewUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewpointDefinitionDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewpointDefinitionDeSerializer.cs index 3035dfbb..62fb718e 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewpointDefinitionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewpointDefinitionDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ViewpointDefinitionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IViewpointDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IViewpointDefinition DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ViewpointDefinitionDeSerializer"); @@ -85,6 +88,33 @@ internal static IViewpointDefinition DeSerialize(JsonElement jsonElement, Serial } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Views.ViewpointDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actorParameter"u8, out var actorParameterProperty)) { foreach (var arrayItem in actorParameterProperty.EnumerateArray()) @@ -1868,8 +1898,176 @@ internal static IViewpointDefinition DeSerialize(JsonElement jsonElement, Serial logger.LogDebug("the viewpointStakeholder Json property was not found in the ViewpointDefinition: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Views.ViewpointDefinition dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ViewpointDefinition: { 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 ViewpointDefinition: { 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 ViewpointDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ViewpointDefinition: { 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 ViewpointDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the ViewpointDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ViewpointDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the ViewpointDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ViewpointDefinition: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ViewpointDefinition: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("reqId"u8, out var reqIdProperty)) + { + dtoInstance.ReqId = reqIdProperty.GetString(); + } + else + { + logger.LogDebug("the reqId Json property was not found in the ViewpointDefinition: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewpointUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewpointUsageDeSerializer.cs index 3a92734e..58ee608c 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewpointUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/ViewpointUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class ViewpointUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IViewpointUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IViewpointUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ViewpointUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IViewpointUsage DeSerialize(JsonElement jsonElement, Serializati } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Views.ViewpointUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actorParameter"u8, out var actorParameterProperty)) { foreach (var arrayItem in actorParameterProperty.EnumerateArray()) @@ -2379,8 +2409,278 @@ internal static IViewpointUsage DeSerialize(JsonElement jsonElement, Serializati logger.LogDebug("the viewpointStakeholder Json property was not found in the ViewpointUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Views.ViewpointUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 ViewpointUsage: { 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 ViewpointUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the ViewpointUsage: { 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 ViewpointUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the ViewpointUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the ViewpointUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the ViewpointUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the ViewpointUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the ViewpointUsage: { 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 ViewpointUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the ViewpointUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the ViewpointUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the ViewpointUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the ViewpointUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the ViewpointUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the ViewpointUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the ViewpointUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the ViewpointUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the ViewpointUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("reqId"u8, out var reqIdProperty)) + { + dtoInstance.ReqId = reqIdProperty.GetString(); + } + else + { + logger.LogDebug("the reqId Json property was not found in the ViewpointUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/WhileLoopActionUsageDeSerializer.cs b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/WhileLoopActionUsageDeSerializer.cs index 1d076c81..9ec9cae7 100644 --- a/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/WhileLoopActionUsageDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/Core/AutoGenDeSerializer/WhileLoopActionUsageDeSerializer.cs @@ -49,13 +49,16 @@ internal static class WhileLoopActionUsageDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored + /// /// /// The used to setup logging /// /// /// an instance of /// - internal static IWhileLoopActionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static IWhileLoopActionUsage DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("WhileLoopActionUsageDeSerializer"); @@ -85,6 +88,33 @@ internal static IWhileLoopActionUsage DeSerialize(JsonElement jsonElement, Seria } } + if (deserializeDerivedProperties) + { + DeserializeDtoIncludingDerivedProperties(dtoInstance, jsonElement, logger); + } + else + { + DeserializeDtoExcludingDerivedProperties(dtoInstance, jsonElement, logger); + } + + return dtoInstance; + } + + /// + /// Deserializes properties of a + /// from a , including derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoIncludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.WhileLoopActionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { if (jsonElement.TryGetProperty("actionDefinition"u8, out var actionDefinitionProperty)) { foreach (var arrayItem in actionDefinitionProperty.EnumerateArray()) @@ -2230,8 +2260,278 @@ internal static IWhileLoopActionUsage DeSerialize(JsonElement jsonElement, Seria logger.LogDebug("the whileArgument Json property was not found in the WhileLoopActionUsage: { Id }", dtoInstance.Id); } + } + + /// + /// Deserializes properties of a + /// from a , excluding derived properties + /// + /// + /// The instance holding deserialized values + /// + /// + /// The that contains the json object + /// + /// + /// The to produce logging statement + /// + private static void DeserializeDtoExcludingDerivedProperties(SysML2.NET.Core.DTO.Systems.Actions.WhileLoopActionUsage dtoInstance, JsonElement jsonElement, ILogger logger) + { + 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 WhileLoopActionUsage: { 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 WhileLoopActionUsage: { 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 WhileLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("direction"u8, out var directionProperty)) + { + dtoInstance.Direction = FeatureDirectionKindDeSerializer.DeserializeNullable(directionProperty.GetString()); + } + else + { + logger.LogDebug("the direction Json property was not found in the WhileLoopActionUsage: { 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 WhileLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isAbstract"u8, out var isAbstractProperty)) + { + if (isAbstractProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsAbstract = isAbstractProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isAbstract Json property was not found in the WhileLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isComposite"u8, out var isCompositeProperty)) + { + if (isCompositeProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsComposite = isCompositeProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isComposite Json property was not found in the WhileLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isConstant"u8, out var isConstantProperty)) + { + if (isConstantProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsConstant = isConstantProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isConstant Json property was not found in the WhileLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isDerived"u8, out var isDerivedProperty)) + { + if (isDerivedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsDerived = isDerivedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isDerived Json property was not found in the WhileLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isEnd"u8, out var isEndProperty)) + { + if (isEndProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsEnd = isEndProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isEnd Json property was not found in the WhileLoopActionUsage: { 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 WhileLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isIndividual"u8, out var isIndividualProperty)) + { + if (isIndividualProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsIndividual = isIndividualProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isIndividual Json property was not found in the WhileLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isOrdered"u8, out var isOrderedProperty)) + { + if (isOrderedProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsOrdered = isOrderedProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isOrdered Json property was not found in the WhileLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isPortion"u8, out var isPortionProperty)) + { + if (isPortionProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsPortion = isPortionProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isPortion Json property was not found in the WhileLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isSufficient"u8, out var isSufficientProperty)) + { + if (isSufficientProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsSufficient = isSufficientProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isSufficient Json property was not found in the WhileLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isUnique"u8, out var isUniqueProperty)) + { + if (isUniqueProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsUnique = isUniqueProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isUnique Json property was not found in the WhileLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("isVariation"u8, out var isVariationProperty)) + { + if (isVariationProperty.ValueKind != JsonValueKind.Null) + { + dtoInstance.IsVariation = isVariationProperty.GetBoolean(); + } + } + else + { + logger.LogDebug("the isVariation Json property was not found in the WhileLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("ownedRelationship"u8, out var ownedRelationshipProperty)) + { + foreach (var arrayItem in ownedRelationshipProperty.EnumerateArray()) + { + if (arrayItem.TryGetProperty("@id"u8, out var ownedRelationshipExternalIdProperty)) + { + var propertyValue = ownedRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwnedRelationship.Add(Guid.Parse(propertyValue)); + } + } + } + } + else + { + logger.LogDebug("the ownedRelationship Json property was not found in the WhileLoopActionUsage: { 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 owningRelationshipExternalIdProperty)) + { + var propertyValue = owningRelationshipExternalIdProperty.GetString(); + + if (propertyValue != null) + { + dtoInstance.OwningRelationship = Guid.Parse(propertyValue); + } + } + } + } + else + { + logger.LogDebug("the owningRelationship Json property was not found in the WhileLoopActionUsage: { Id }", dtoInstance.Id); + } + + if (jsonElement.TryGetProperty("portionKind"u8, out var portionKindProperty)) + { + dtoInstance.PortionKind = PortionKindDeSerializer.DeserializeNullable(portionKindProperty.GetString()); + } + else + { + logger.LogDebug("the portionKind Json property was not found in the WhileLoopActionUsage: { Id }", dtoInstance.Id); + } - return dtoInstance; } } } diff --git a/SysML2.NET.Serializer.Json/DeSerializer.cs b/SysML2.NET.Serializer.Json/DeSerializer.cs index 928e7a48..a66c216b 100644 --- a/SysML2.NET.Serializer.Json/DeSerializer.cs +++ b/SysML2.NET.Serializer.Json/DeSerializer.cs @@ -77,10 +77,11 @@ public DeSerializer(ILoggerFactory loggerFactory = null) /// /// The to use /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored /// /// an /// - public IEnumerable DeSerialize(Stream stream, SerializationModeKind serializationModeKind, SerializationTargetKind serializationTargetKind) + public IEnumerable DeSerialize(Stream stream, SerializationModeKind serializationModeKind, SerializationTargetKind serializationTargetKind, bool deserializeDerivedProperties) { var sw = Stopwatch.StartNew(); @@ -93,10 +94,10 @@ public IEnumerable DeSerialize(Stream stream, SerializationModeKind seria switch (root.ValueKind) { case JsonValueKind.Object: - result.Add(this.DeserializeObject(root, serializationModeKind, serializationTargetKind)); + result.Add(this.DeserializeObject(root, serializationModeKind, serializationTargetKind, deserializeDerivedProperties)); break; case JsonValueKind.Array: - result.AddRange(this.DeserializeArray(root, serializationModeKind, serializationTargetKind)); + result.AddRange(this.DeserializeArray(root, serializationModeKind, serializationTargetKind, deserializeDerivedProperties)); break; default: throw new SerializationException(); @@ -107,7 +108,7 @@ public IEnumerable DeSerialize(Stream stream, SerializationModeKind seria return result; } - + /// /// Asynchronously deserializes the JSON stream to an /// @@ -120,13 +121,14 @@ public IEnumerable DeSerialize(Stream stream, SerializationModeKind seria /// /// The to use /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored /// /// The used to cancel the operation /// /// /// an /// - public async Task> DeSerializeAsync(Stream stream, SerializationModeKind serializationModeKind, SerializationTargetKind serializationTargetKind, CancellationToken cancellationToken) + public async Task> DeSerializeAsync(Stream stream, SerializationModeKind serializationModeKind, SerializationTargetKind serializationTargetKind, bool deserializeDerivedProperties, CancellationToken cancellationToken) { var sw = Stopwatch.StartNew(); @@ -141,10 +143,10 @@ public async Task> DeSerializeAsync(Stream stream, Serializat switch (root.ValueKind) { case JsonValueKind.Object: - result.Add(this.DeserializeObject(root, serializationModeKind, serializationTargetKind)); + result.Add(this.DeserializeObject(root, serializationModeKind, serializationTargetKind, deserializeDerivedProperties)); break; case JsonValueKind.Array: - result.AddRange(this.DeserializeArray(root, serializationModeKind, serializationTargetKind)); + result.AddRange(this.DeserializeArray(root, serializationModeKind, serializationTargetKind, deserializeDerivedProperties)); break; default: throw new SerializationException(); @@ -168,10 +170,11 @@ public async Task> DeSerializeAsync(Stream stream, Serializat /// /// The to use /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored /// /// an instance of /// - private IData DeserializeObject(JsonElement jsonObject, SerializationModeKind serializationModeKind, SerializationTargetKind serializationTargetKind) + private IData DeserializeObject(JsonElement jsonObject, SerializationModeKind serializationModeKind, SerializationTargetKind serializationTargetKind, bool deserializeDerivedProperties) { if (jsonObject.ValueKind != JsonValueKind.Object) { @@ -182,24 +185,24 @@ private IData DeserializeObject(JsonElement jsonObject, SerializationModeKind se { var typeName = typeElement.GetString(); - Func func; + Func func; if (serializationTargetKind == SerializationTargetKind.PSM) { if (ApiDeSerializationProvider.IsTypeSupported(typeName)) { func = ApiDeSerializationProvider.Provide(typeName); - return func(jsonObject, serializationModeKind, this.loggerFactory); + return func(jsonObject, serializationModeKind, deserializeDerivedProperties, this.loggerFactory); } else { func = DeSerializationProvider.Provide(typeName); - return func(jsonObject, serializationModeKind, this.loggerFactory); + return func(jsonObject, serializationModeKind,deserializeDerivedProperties, this.loggerFactory); } } func = DeSerializationProvider.Provide(typeName); - return func(jsonObject, serializationModeKind, this.loggerFactory); + return func(jsonObject, serializationModeKind, deserializeDerivedProperties, this.loggerFactory); } throw new SerializationException("The @type Json property is not available, the DeSerializer cannot be used to deserialize this JsonElement"); @@ -217,10 +220,11 @@ private IData DeserializeObject(JsonElement jsonObject, SerializationModeKind se /// /// The to use /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored /// /// an /// - private IEnumerable DeserializeArray(JsonElement jsonArray, SerializationModeKind serializationModeKind, SerializationTargetKind serializationTargetKind) + private IEnumerable DeserializeArray(JsonElement jsonArray, SerializationModeKind serializationModeKind, SerializationTargetKind serializationTargetKind, bool deserializeDerivedProperties) { if (jsonArray.ValueKind != JsonValueKind.Array) { @@ -231,7 +235,7 @@ private IEnumerable DeserializeArray(JsonElement jsonArray, Serialization foreach (var jsonElement in jsonArray.EnumerateArray()) { - var dataItem = this.DeserializeObject(jsonElement, serializationModeKind, serializationTargetKind); + var dataItem = this.DeserializeObject(jsonElement, serializationModeKind, serializationTargetKind, deserializeDerivedProperties); result.Add(dataItem); } diff --git a/SysML2.NET.Serializer.Json/IDeSerializer.cs b/SysML2.NET.Serializer.Json/IDeSerializer.cs index 499d104b..8694ab1a 100644 --- a/SysML2.NET.Serializer.Json/IDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/IDeSerializer.cs @@ -45,10 +45,11 @@ public interface IDeSerializer /// /// The to use /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored /// /// an /// - IEnumerable DeSerialize(Stream stream, SerializationModeKind serializationModeKind, SerializationTargetKind serializationTargetKind); + IEnumerable DeSerialize(Stream stream, SerializationModeKind serializationModeKind, SerializationTargetKind serializationTargetKind, bool deserializeDerivedProperties); /// /// Asynchronously deserializes the JSON stream to an @@ -62,12 +63,13 @@ public interface IDeSerializer /// /// The to use /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored /// /// The used to cancel the operation /// /// /// an /// - Task> DeSerializeAsync(Stream stream, SerializationModeKind serializationModeKind, SerializationTargetKind serializationTargetKind, CancellationToken cancellationToken); + Task> DeSerializeAsync(Stream stream, SerializationModeKind serializationModeKind, SerializationTargetKind serializationTargetKind, bool deserializeDerivedProperties, CancellationToken cancellationToken); } } diff --git a/SysML2.NET.Serializer.Json/PIM/ApiDeSerializationProvider.cs b/SysML2.NET.Serializer.Json/PIM/ApiDeSerializationProvider.cs index 9d564f19..7c299aba 100644 --- a/SysML2.NET.Serializer.Json/PIM/ApiDeSerializationProvider.cs +++ b/SysML2.NET.Serializer.Json/PIM/ApiDeSerializationProvider.cs @@ -38,9 +38,9 @@ internal static class ApiDeSerializationProvider /// /// a dictionary that provides delegates for deserialization /// - private static readonly Dictionary> + private static readonly Dictionary> DeSerializerActionMap = - new Dictionary> + new Dictionary> { { "Branch", BranchDeserializer.DeSerialize }, { "Commit", CommitDeSerializer.DeSerialize }, @@ -50,19 +50,19 @@ private static readonly Dictionary - /// Provides the delegate for the + /// Provides the delegate for the /// that is to be deserialized /// /// /// The name of the subject that is to be serialized /// /// - /// A Delegate of + /// A Delegate of /// /// /// Thrown when the is not supported. /// - internal static Func Provide(string typeName) + internal static Func Provide(string typeName) { if (!DeSerializerActionMap.TryGetValue(typeName, out var func)) { diff --git a/SysML2.NET.Serializer.Json/PIM/BranchDeserializer.cs b/SysML2.NET.Serializer.Json/PIM/BranchDeserializer.cs index ccc0bc71..77b7be7f 100644 --- a/SysML2.NET.Serializer.Json/PIM/BranchDeserializer.cs +++ b/SysML2.NET.Serializer.Json/PIM/BranchDeserializer.cs @@ -44,13 +44,14 @@ internal static class BranchDeserializer /// /// enumeration specifying what kind of serialization shall be used /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignoredAsserts that the deserializer should deserialize derived properties if present or if they are ignored /// /// The used to setup logging /// /// /// an instance of /// - internal static Branch DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static Branch DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("BranchDeserializer"); diff --git a/SysML2.NET.Serializer.Json/PIM/CommitDeSerializer.cs b/SysML2.NET.Serializer.Json/PIM/CommitDeSerializer.cs index 634c7f01..bade28ac 100644 --- a/SysML2.NET.Serializer.Json/PIM/CommitDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/PIM/CommitDeSerializer.cs @@ -44,13 +44,14 @@ internal static class CommitDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored /// /// The used to setup logging /// /// /// an instance of /// - internal static Commit DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static Commit DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("CommitDeSerializer"); diff --git a/SysML2.NET.Serializer.Json/PIM/DataIdentityDeSerializer.cs b/SysML2.NET.Serializer.Json/PIM/DataIdentityDeSerializer.cs index 75413a99..9f67709d 100644 --- a/SysML2.NET.Serializer.Json/PIM/DataIdentityDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/PIM/DataIdentityDeSerializer.cs @@ -44,13 +44,14 @@ internal static class DataIdentityDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored /// /// The used to setup logging /// /// /// an instance of /// - internal static DataIdentity DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static DataIdentity DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("DataIdentityDeSerializer"); diff --git a/SysML2.NET.Serializer.Json/PIM/DataVersionDeSerializer.cs b/SysML2.NET.Serializer.Json/PIM/DataVersionDeSerializer.cs index a2ca748d..d72ed502 100644 --- a/SysML2.NET.Serializer.Json/PIM/DataVersionDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/PIM/DataVersionDeSerializer.cs @@ -45,13 +45,14 @@ internal static class DataVersionDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored /// /// The used to setup logging /// /// /// an instance of /// - internal static DataVersion DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static DataVersion DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("DataVersionDeSerializer"); @@ -107,7 +108,7 @@ internal static DataVersion DeSerialize(JsonElement jsonElement, SerializationMo if (jsonElement.TryGetProperty("identity"u8, out JsonElement identityObject)) { - dtoInstance.Identity = DataIdentityDeSerializer.DeSerialize(identityObject, serializationModeKind, loggerFactory); + dtoInstance.Identity = DataIdentityDeSerializer.DeSerialize(identityObject, serializationModeKind, deserializeDerivedProperties, loggerFactory); } else { @@ -121,7 +122,7 @@ internal static DataVersion DeSerialize(JsonElement jsonElement, SerializationMo var typeName = typeElement.GetString(); var func = DeSerializationProvider.Provide(typeName); - dtoInstance.Payload = func(payloadObject, serializationModeKind, loggerFactory); + dtoInstance.Payload = func(payloadObject, serializationModeKind,deserializeDerivedProperties, loggerFactory); } } else diff --git a/SysML2.NET.Serializer.Json/PIM/ProjectDeSerializer.cs b/SysML2.NET.Serializer.Json/PIM/ProjectDeSerializer.cs index 90174e69..b4f012b2 100644 --- a/SysML2.NET.Serializer.Json/PIM/ProjectDeSerializer.cs +++ b/SysML2.NET.Serializer.Json/PIM/ProjectDeSerializer.cs @@ -44,13 +44,14 @@ internal static class ProjectDeSerializer /// /// enumeration specifying what kind of serialization shall be used /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored /// /// The used to setup logging /// /// /// an instance of /// - internal static Project DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static Project DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("ProjectDeSerializer"); diff --git a/SysML2.NET.Serializer.Json/PIM/TagDeserializer.cs b/SysML2.NET.Serializer.Json/PIM/TagDeserializer.cs index d52c6818..1f838f46 100644 --- a/SysML2.NET.Serializer.Json/PIM/TagDeserializer.cs +++ b/SysML2.NET.Serializer.Json/PIM/TagDeserializer.cs @@ -44,13 +44,14 @@ internal static class TagDeserializer /// /// enumeration specifying what kind of serialization shall be used /// + /// Asserts that the deserializer should deserialize derived properties if present or if they are ignored /// /// The used to setup logging /// /// /// an instance of /// - internal static Tag DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, ILoggerFactory loggerFactory = null) + internal static Tag DeSerialize(JsonElement jsonElement, SerializationModeKind serializationModeKind, bool deserializeDerivedProperties, ILoggerFactory loggerFactory = null) { var logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger("TagDeserializer");