diff --git a/NewApi.Tests/BaseIsAnInterfaceTests.cs b/NewApi.Tests/BaseIsAnInterfaceTests.cs index 6b31001..f86a7fb 100644 --- a/NewApi.Tests/BaseIsAnInterfaceTests.cs +++ b/NewApi.Tests/BaseIsAnInterfaceTests.cs @@ -51,7 +51,6 @@ public void ConcurrentThreadTest() [Test] public void UnknownMappingFails() { - Assert.Fail("Not ready"); var exception = Assert.Throws(() => JsonSerializer.Deserialize("{\"Sound\":\"Scream\"}")); Assert.AreEqual("Could not create an instance of type JsonSubTypes.Tests.BaseIsAnInterfaceTests+IAnimal. Type is an interface or abstract class and cannot be instantiated. Path 'Sound', line 1, position 9.", exception.Message); } diff --git a/NewApi.Tests/DemoAlternativeTypePropertyNameTests.cs b/NewApi.Tests/DemoAlternativeTypePropertyNameTests.cs index 560d07b..2c232a2 100644 --- a/NewApi.Tests/DemoAlternativeTypePropertyNameTests.cs +++ b/NewApi.Tests/DemoAlternativeTypePropertyNameTests.cs @@ -97,7 +97,6 @@ public void DemoBaseWhenNull() [Test] public void ArbitraryConstructorShouldNotBeCalled() { - Assert.Fail("Not ready"); Animal deserializeObject = null; try { diff --git a/NewApi/JsonSubtypes2.cs b/NewApi/JsonSubtypes2.cs index f3366c5..9490986 100644 --- a/NewApi/JsonSubtypes2.cs +++ b/NewApi/JsonSubtypes2.cs @@ -66,7 +66,6 @@ public interface IJsonSubtypes } public class JsonSubtypes : JsonConverter, IJsonSubtypes { - protected readonly string JsonDiscriminatorPropertyName; public JsonSubtypes() @@ -203,7 +202,7 @@ private Type GetType(JsonDocument jObject, Type parentType, JsonSerializerOption { Type targetType = parentType; IJsonSubtypes lastTypeResolver = null; - IJsonSubtypes currentTypeResolver = currentTypeResolver = GetTypeResolver(ToTypeInfo(targetType), serializer.Converters.OfType()); + IJsonSubtypes currentTypeResolver = GetTypeResolver(ToTypeInfo(targetType), serializer.Converters.OfType()); var jsonConverterCollection = serializer.Converters.OfType().ToList(); while (currentTypeResolver != null && currentTypeResolver != lastTypeResolver) @@ -270,18 +269,15 @@ private static bool TryGetValueInJson(JsonDocument jObject, string propertyName, return true; } - JsonProperty matchingProperty = jObject + var objectEnumerator = jObject .RootElement - .EnumerateObject() - .FirstOrDefault(jsonProperty => string.Equals(jsonProperty.Name, propertyName, StringComparison.OrdinalIgnoreCase)); - - if (string.Equals(matchingProperty.Name, propertyName, StringComparison.OrdinalIgnoreCase)) + .EnumerateObject(); + foreach (var jsonProperty in objectEnumerator.Where(jsonProperty => string.Equals(jsonProperty.Name, propertyName, StringComparison.OrdinalIgnoreCase))) { - return false; + value = jsonProperty.Value; + return true; } - - value = matchingProperty.Value; - return true; + return false; } private static Type GetTypeByName(string typeName, TypeInfo parentType)