Skip to content

Commit

Permalink
Support for System.Text.Json in .NET Core 3 #85
Browse files Browse the repository at this point in the history
allow two test to execute
  • Loading branch information
manuc66 committed Feb 23, 2020
1 parent 7c9df3e commit a445fc1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
1 change: 0 additions & 1 deletion NewApi.Tests/BaseIsAnInterfaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public void ConcurrentThreadTest()
[Test]
public void UnknownMappingFails()
{
Assert.Fail("Not ready");
var exception = Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<IAnimal>("{\"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);
}
Expand Down
1 change: 0 additions & 1 deletion NewApi.Tests/DemoAlternativeTypePropertyNameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public void DemoBaseWhenNull()
[Test]
public void ArbitraryConstructorShouldNotBeCalled()
{
Assert.Fail("Not ready");
Animal deserializeObject = null;
try
{
Expand Down
18 changes: 7 additions & 11 deletions NewApi/JsonSubtypes2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public interface IJsonSubtypes
}
public class JsonSubtypes<T> : JsonConverter<T>, IJsonSubtypes
{

protected readonly string JsonDiscriminatorPropertyName;

public JsonSubtypes()
Expand Down Expand Up @@ -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>());
IJsonSubtypes currentTypeResolver = GetTypeResolver(ToTypeInfo(targetType), serializer.Converters.OfType<IJsonSubtypes>());

var jsonConverterCollection = serializer.Converters.OfType<IJsonSubtypes>().ToList();
while (currentTypeResolver != null && currentTypeResolver != lastTypeResolver)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a445fc1

Please sign in to comment.