none
deserialization/serialization hooks in 5.4 RRS feed

  • Question

  • The atom payload is massive, so we need to move to JSON. However, there is a problem with the WCF Data services server, where it falls over when a property is included in the payload that it doesn't expect... So, we have to resort to using the WritingEntity event handler (Google: Customizing Serialization of Entities in the ADO.NET Data Services Client Library)


    However, this only works with atom.


    In the 5.4 release blog post it said there are new deserialization/serialization hooks, what are they, can they be used with JSON?
    Thursday, May 2, 2013 2:17 PM

Answers

  • Yes we have added hooks. We still need to add more documentation on this. We added a class called Configurations on the DataServiceContext. Then there is Type DataServiceResponseConfigurations with a property ResponsePipeline on Configurations and there is DataServiceRequestConfigurations RequestPipeline property. Basically we are slowly attempting to introduce the concept of the request/response pipeline on the client. Below is a snippet of code that removes a property from an ODataEntry. This will happen prior to the entity being materialized so it will be as if the property doesn't exist.

    dataServiceContext.Configurations.ResponsePipeline.OnEntryEnded((a =>

                    {

                        Type entityType = dataServiceContext.ResolveType(a.Entry.TypeName);

                        if (typeof(Product).IsAssignableFrom(entityType))

                        {

                            var properties = a.Entry.Properties as List<ODataProperty>;

                            if (properties == null)

                            {

                                properties = new List<ODataProperty>(a.Entry.Properties);

                            }

                            var odataPropertyToRemove = properties.Single(p => p.Name == "Description");

                            properties.Remove(odataPropertyToRemove);

                            a.Entry.Properties = properties;

                            a.Entry.RemoveProperties("Description");

                        }

                    }));

    There are a bunch of callbacks, and yes they work for all formats, json and atom. For your usage I would look at the RequestPipeline (where things are written to the request to be sent) and make modifications there.

    dataServiceContext.Configurations.RequestPipeline.OnEntryEnding((a =>

                    {

                       // Put code in here changing the ODataEntry here a.Entry    

                    }

    Let me know if you have any other questions. There are a ton of other cools things you can do with this functionality we introduced. You can make multiple configurations and they will be processed in the order they are registered creating your own pipeline of transformations.

    Thanks,

    Chris Robinson - WCF Data Services 


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Thursday, May 2, 2013 6:46 PM
    Moderator