Search code examples
jsonodata

OData.net specifying a `$format` parameter to the service call


I'm using the OData.net client and consuming a service that uses the "$format" query string parameter to switch the layout of how the JSON data is returned.

I am unable to pass this parameter to the context. Using .AddQueryOption("$format", "CustomJSON") yields and error to set the format in the context object but there are no setters anywhere in the format object.

The format coming back is proper JSON, is there a way to have OData.net send a $format parameter and use the JSON parser on the results?


Solution

  • OData client doesn't support custom format. So you cannot send the request by AddQueryOption("$format", "CustomJson").

    1. It will consider it as an invalid media type.
    2. Even if you use response pipeline to set the media type resolver, client still fails when materializing the response payload. It will report "not supported content type" error.