Reputation: 222
I am trying to upgrade OData package (Microsoft.AspNet.OData
) from v5.9 to v6.0 and my code break because I have a class that extends ODataEntityTypeSerializer
.
I search for that in object browser and it was removed. When I back to v5.9.1 it works.
Is there a replacement for ODataEntityTypeSerializer
in new 6.0 version or this is just a compatibility break?
My derived class is a way to prevent null
value serialization.
I write the new provider to treat null
based on this response on SO.
public class NullEntityTypeSerializer : ODataEntityTypeSerializer
{
public NullEntityTypeSerializer(ODataSerializerProvider serializerProvider)
: base(serializerProvider)
{ }
public override void WriteObjectInline(object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext)
{
if (graph != null)
{
base.WriteObjectInline(graph, expectedType, writer, writeContext);
}
}
}
UPDATE (jul/18): The problem with SingleResult.Create()
that generate this work around was fixed in v7.0 and this is not necessary anymore. Check https://github.com/OData/WebApi/issues/170
Upvotes: 4
Views: 901
Reputation: 63
Look at the same issue here: https://github.com/OData/WebApi/issues/995
You call this method to get the IServiceProvider: https://github.com/OData/WebApi/blob/master/src/System.Web.OData/Extensions/HttpRequestMessageExtensions.cs#L234
And also need a custom IContentNegotiator
Upvotes: 1
Reputation: 164
According to https://odata.github.io/WebApi/#07-18-6-0 You should use ODataResourceSerializer.
Upvotes: 1