How to get ODataSerializerProvider to respond all request types?
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 864
- Forks
- 467
- PR merge metrics
- No merged PRs in 30d
Description
I have created a customized ODataSerializerProvider in order to change odata output using ODataEntityTypeSerializer. But my custom ODataEntityTypeSerializer does not fire on every request. The only differences I guess affect this is Request Headers Accept and Accept-Encoding.
How I can get ODataSerializerProvider to respond all request types?
Here it is my codes:
public class CustomDefaultODataSerializerProvider : DefaultODataSerializerProvider
{
CustomODataEntityTypeSerializer _customODataEntityTypeSerializer;
public CustomDefaultODataSerializerProvider()
{
_customODataEntityTypeSerializer = new CustomODataEntityTypeSerializer(this);
}
public override ODataEdmTypeSerializer GetEdmTypeSerializer(IEdmTypeReference edmType)
{
if (edmType.IsEntity())
{
return _customODataEntityTypeSerializer;
}
return base.GetEdmTypeSerializer(edmType);
}
}
public class CustomODataEntityTypeSerializer : ODataEntityTypeSerializer
{
public CustomODataEntityTypeSerializer(ODataSerializerProvider serializerProvider) : base(serializerProvider)
{
}
public override void WriteObjectInline(object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext)
{
//here it is which place I need to be fired for all requests
}
}
registration:
var odataFormatters = ODataMediaTypeFormatters.Create(new CustomDefaultODataSerializerProvider(), new DefaultODataDeserializerProvider());
config.Formatters.InsertRange(0, odataFormatters);
This is the header that works:
Accept:application/atomsvc+xml;q=0.8, application/json;odata=verbose;q=0.5, */*;q=0.1
Accept-Encoding:gzip, deflate, sdch, br Accept-Language:en-US,en;q=0.8 Connection:keep-alive
And this is the header that does not work:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch, br Accept-Language:en-US,en;q=0.8 Cache-Control:no-cache Connection:keep-alive
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with CustomDefaultODataSerializerProvider, CustomODataEntityTypeSerializer, and the ODataMediaTypeFormatters registration shown in the issue. Reproduce the requests with the two Accept headers and trace formatter and serializer selection; done means identifying why WriteObjectInline is reached for one request but not the other and documenting the supported response behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100