Why is everything OneOrMany<T>, even things that would logically only have 1 value? #205
-
QuestionIn It seems all properties are marked as Schema ObjectsWhich schema.org object is this about if any? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Each of the schema types are generated by a tool, which takes a JSON file from schema.org. The JSON file doesn't specify whether some properties are logically only ever a single value or not. You will find a lot of properties like this though there are also many properties where multiples could exist (eg. author). Without some kind of mapping to determine what makes logical sense or not, defaulting to the idea that anything could be multiple values makes life a lot easier. When dealing with Hopefully that answers your question! |
Beta Was this translation helpful? Give feedback.
-
Ok, that is clear. Out of interest, though: do you know whether there are many apps that use these schema.org models directly as their view models? Or is it more common to have converters that convert between the schema.org models and view models (I suspect this, but not sure)? |
Beta Was this translation helpful? Give feedback.
-
I don't have any firm numbers either way. I'd suspect for people who are generating JSON+LD for web pages, they might use the Schema object directly as it saves them from unnecessary conversion and serialization logic - this is what I do for my sites. Schema.NET is smart enough to realise when you have one value in a The only other example that comes to mind is another thing I'm working on, I have a product where the API returns Schema.org types where the API model itself is the Schema.NET type. I do this as I would have needed to re-implement every possible type in Schema.NET to have a stable view model. Instead, I decided whatever the latest official version of Schema.org is will be what I use. |
Beta Was this translation helpful? Give feedback.
-
Thank you! |
Beta Was this translation helpful? Give feedback.
Each of the schema types are generated by a tool, which takes a JSON file from schema.org. The JSON file doesn't specify whether some properties are logically only ever a single value or not.
You will find a lot of properties like this though there are also many properties where multiples could exist (eg. author). Without some kind of mapping to determine what makes logical sense or not, defaulting to the idea that anything could be multiple values makes life a lot easier.
When dealing with
OneOrMany
though, you don't have to worry too much about it being a single value or many values. It has implicit conversions from a singularT
to aOneOrMany<T>
. It has these implicit conversions the o…