Closed AlizerUncaged closed 8 months ago
Hi @AlizerUncaged - so the cast doesn't work because Uri
is a .NET system type which doesn't implement the IThing
interface. The root of your problem is the same thing I've mentioned here - what Google is showing in their example isn't following the schema.org standard. Our types are generated from the standard, not things Google decides to deviate from it.
We can see in the schema.org docs that item
is only of type Thing
.
Drilling down further into the item
property docs itself, it shows a JSON-LD example of how you would set the URL:
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement":
[
{
"@type": "ListItem",
"position": 1,
"item":
{
"@id": "https://example.com/dresses",
"name": "Dresses"
}
},
{
"@type": "ListItem",
"position": 2,
"item":
{
"@id": "https://example.com/dresses/real",
"name": "Real Dresses"
}
}
]
}
</script>
And the screenshot of the Google documentation that you put in your comment on the other issue says that this is valid:
So all you need to do is use:
new ListItem
{
Item = new Thing
{
Id = new Uri(formattedUrl + "_b")
}
}
To be clear, I don't even disagree that item
probably could take a Url
as an alternative type but that isn't up to me - that is up to schema.org and unless you get them to change, we can't change.
Describe the bug
I have the code like below to create a BreadcrumbList schema![image](https://github.com/RehanSaeed/Schema.NET/assets/86959368/56e3b167-e86f-4928-839c-6c220e2a15e5)
my problem is that the ListItem Item property accepts a
OneOrMany<IThing>
type which if I donew OneOrMany<IThing>((IThing)new Uri(formattedUrl))
causes aSystem.InvalidCastException
Steps to reproduce
create a breadcrumblist object
Expected behaviour
It should allow string or a Uri in the Item field, Google seems to just accept a Uri in the![image](https://github.com/RehanSaeed/Schema.NET/assets/86959368/4663a7fd-4501-49c7-877c-bf29491affa3)
item
field, it will hurt SEO if we're not following GoogleSchema objects
https://schema.org/ListItem