You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Okay, so obviously I never consider such usage of the serialiser and it expects input which will serialise to JSON object (JObject.FromObject()). A dictionary is handled as a JSON object because it is essentially a JS map and not an array.
I wouldn't want to overthink this at this point. Essentially JSON-LD can serialise arrays in two ways. First is a plain array, which prevents the use of a global @context
[
{
"@id": "http://example.com/resource"
}
]
The second option enforces wrapping the array in a @graph object:
I'm pretty sure that for simplicity's sake I'd want to always do the latter and extend the entity serializer with a method JObject Serialize<TElement>(IEnumerable<TElement> entities, SerializationOptions options = null); This method will wrap the array in a @graph and apply the context for the element's type.
Could also be an extension.
Seems to be an issue with serialization of lists?
List persons = new List();
persons.Add(new Person(....
persons.Add(new Person(....
IEntitySerializer serializer = new EntitySerializer();
dynamic json = serializer.Serialize(persons);
Results in the following error: Object Serialized to Array. JObject instance expected.
Funnily enough seems to serialize a dictionary of persons ok though.
The text was updated successfully, but these errors were encountered: