Schema.org objects turned into strongly typed C# POCO classes for use in .NET. All classes can be serialized into JSON/JSON-LD and XML, typically used to represent structured data in the head section of html page.
MIT License
640
stars
80
forks
source link
A null or whitespace string passed into Values<T1, T2*> causes HasValueX to return true #675
string json = """
{
"@context": "https://schema.org",
"@type": "Reservation",
"reservationId": "1",
"totalPrice": ""
}
""";
Schema.NET.Reservation reservation = Schema.NET.SchemaSerializer.DeserializeObject<Schema.NET.Reservation>(json)!;
_ = reservation.TotalPrice.Value3.Count == 0 ? "Correct, totalPrice should be an empty collection" : throw new InvalidDataException("totalPrice should be an empty collection");
_ = !reservation.TotalPrice.HasValue3 ? "Correct, totalPrice should not have any values" : throw new InvalidDataException("totalPrice should return false for HasValue3");
Deserialise simple Reservation where totalPrice is an empty string.
Test that Reservation.TotalPrice has no values for values property 3 (string).
Test that Reservation.TotalPrice returns false for HasValue3 (optionally the same test for HasValue).
Observe that InvalidDataException is thrown with the message totalPrice should return false for HasValue3.
Expected behaviour
Reservation.TotalPrice.HasValue3 should return false, not true.
Describe the bug
When the
Values(params object[] items)
orValues(IEnumerable<object?> items)
constructors are used, and:Tn
is a string and the value is eithernull
or a whitespace string; orTn
is a nullable type; thenThe constructor logic will evaluate
HasValueX
before assigning toValueX
, whereValueX
returns an empty collection post-OneOrMany<Tn>
cast.Steps to reproduce
A simple reproducible sample can be achieved using https://schema.org/Reservation:
Reservation
wheretotalPrice
is an empty string.Reservation.TotalPrice
has no values for values property 3 (string
).Reservation.TotalPrice
returnsfalse
forHasValue3
(optionally the same test forHasValue
).InvalidDataException
is thrown with the messagetotalPrice should return false for HasValue3
.Expected behaviour
Reservation.TotalPrice.HasValue3
should returnfalse
, nottrue
.Schema objects