asp.net web api - WebAPI v2 - JSON Serialization for OData expand causes $type to be incorrect -
i have updated mvc4/webapi v1 application mvc5 + webapi2..
seems after upgrade json.net serializer no longer include proper $type requests make use of odata $expand method. see below example of mean...
correct:
request: http://url.com/api/studies/277/sites
response:
{ $id: "1" $type: "lgcydapi.domain.model.studysitewithcontacts, lgcydapi.domain.model" contacts: [ { $id: "2" $type: "lgcydapi.domain.model.contactrelatedtosite, lgcydapi.domain.model" contactid: -38445 }], siteid: 38445 }
incorrect:
request: http://url.com/api/studies/277/sites?$expand=contacts
response:
{ $id: "1" $type: "system.collections.generic.dictionary`2[[system.string, mscorlib],[system.object, mscorlib]], mscorlib" contacts: [ { $id: "2" $type: "system.collections.generic.dictionary`2[[system.string, mscorlib],[system.object, mscorlib]], mscorlib" contactid: -38445 }], siteid: 38445}
along mvc , webapi assemblies, updated json.net 5.0.6 6.0.3 thought problem.. however, reverted v5 , didn't fix problem i'm on v6. updated odata nugets - current versions microsoft.data.odata=5.6.0 , microsoft.aspnet.webapi.odata=5.1.2.
json serializer settings:
pconfiguration.formatters.jsonformatter.serializersettings.referenceloophandling = referenceloophandling.serialize; pconfiguration.formatters.jsonformatter.serializersettings.preservereferenceshandling = preservereferenceshandling.objects; pconfiguration.formatters.jsonformatter.serializersettings.typenamehandling = typenamehandling.objects; pconfiguration.formatters.jsonformatter.serializersettings.converters.add(new newtonsoft.json.converters.stringenumconverter());
the $type in response payload actual object serialized.
with $expand applied on result, structure of returned object changed lgcydapi.domain.model.studysitewithcontacts
selectexpandwrapper
.
so can't expected sites type $expand applied.
for selectexpandwrapper
structure, check this:
https://aspnetwebstack.codeplex.com/wikipage?title=%24select%20and%20%24expand%20support
Comments
Post a Comment