From c9f52f5dfb35812ace320a3659a738e2138d9282 Mon Sep 17 00:00:00 2001 From: Eric Wassail Date: Mon, 11 Dec 2023 17:03:55 -0500 Subject: [PATCH 1/2] handle folders which look like elemetns but aren't --- .../src/Serialization/JSON/JsonInheritanceConverter.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Elements/src/Serialization/JSON/JsonInheritanceConverter.cs b/Elements/src/Serialization/JSON/JsonInheritanceConverter.cs index d240af76e..0cc1b8f2f 100644 --- a/Elements/src/Serialization/JSON/JsonInheritanceConverter.cs +++ b/Elements/src/Serialization/JSON/JsonInheritanceConverter.cs @@ -358,7 +358,7 @@ private System.Type GetObjectSubtype(System.Type objectType, string discriminato return typeof(GeometricElement); } // If nothing else has worked, see if it has an ID and treat it as a generic element - if (jObject.TryGetValue("Id", out _)) + if (jObject.TryGetValue("Id", out _) && DoesNotLookLikeFolder(objectType)) { return typeof(Element); } @@ -367,5 +367,10 @@ private System.Type GetObjectSubtype(System.Type objectType, string discriminato // is to return the base objectType if a derived type can't be found. return objectType; } + + private static bool DoesNotLookLikeFolder(Type objectType) + { + return objectType.GetProperty("Files") == null; + } } } \ No newline at end of file From 629128418d0d5919991f228e212e8e0c6ec209e3 Mon Sep 17 00:00:00 2001 From: Eric Wassail Date: Tue, 12 Dec 2023 09:36:22 -0500 Subject: [PATCH 2/2] only do elements fall back in the presence of a discriminator --- .../src/Serialization/JSON/JsonInheritanceConverter.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Elements/src/Serialization/JSON/JsonInheritanceConverter.cs b/Elements/src/Serialization/JSON/JsonInheritanceConverter.cs index 0cc1b8f2f..ad27c10d9 100644 --- a/Elements/src/Serialization/JSON/JsonInheritanceConverter.cs +++ b/Elements/src/Serialization/JSON/JsonInheritanceConverter.cs @@ -353,12 +353,12 @@ private System.Type GetObjectSubtype(System.Type objectType, string discriminato // If it's not in the type cache see if it's got a representation. // Import it as a GeometricElement. - if (jObject.TryGetValue("Representation", out _)) + if (jObject.TryGetValue("Representation", out _) && discriminator != null) { return typeof(GeometricElement); } // If nothing else has worked, see if it has an ID and treat it as a generic element - if (jObject.TryGetValue("Id", out _) && DoesNotLookLikeFolder(objectType)) + if (jObject.TryGetValue("Id", out _) && discriminator != null) { return typeof(Element); } @@ -367,10 +367,5 @@ private System.Type GetObjectSubtype(System.Type objectType, string discriminato // is to return the base objectType if a derived type can't be found. return objectType; } - - private static bool DoesNotLookLikeFolder(Type objectType) - { - return objectType.GetProperty("Files") == null; - } } } \ No newline at end of file