Wednesday 21 August 2013

Emit odata.type field with DataContractJsonSerializer?

Emit odata.type field with DataContractJsonSerializer?

Is there a way to make DataContractJsonSerializer emit the "odata.type"
field required when posting an OData entity into a collection that
supports multiple entity types (hierarchy per table)?
If I construct DataContractJsonSerializer with a settings object with
EmitTypeInformation set to Always, it emits a "__type" field in the
output, but that's not the field name needed for OData and the format of
the value is wrong as well.
Is there any way to hook into the DataContractJsonSerializer pipeline to
inject the desired "odata.type" field into the serialization output?
It would be such a hack to have to parse the serialization output in order
to inject the field. How does WCF Data Services do it? Not using
DataContractJsonSerializer is my guess.

No comments:

Post a Comment