public async override Task<InputFormatterResult> ReadRequestBodyAsync(InputFormatterContext context, Encoding selectedEncoding)
        {
            var serializationStrategies = DataContractSerializationStrategies.Create(context.ModelType);

            string content;
            using (var reader = new StreamReader(context.HttpContext.Request.Body, selectedEncoding))
            {
                Task<string> contentReading = reader.ReadToEndAsync();
                content = await contentReading;
            }

            using (MemoryStream stream = new MemoryStream())
            {
                stream.Write(Encoding.UTF8.GetBytes(content));
                content = null;
                stream.Position = 0;

                object composedInstance = serializationStrategies.ComposedModelJsonSerializer.ReadObject(stream);
                var composedInstances = composedInstance as IEnumerable;
                if (composedInstances != null)
                {
                    foreach (var item in composedInstances)
                    {
                        var extensibleInstance = item as IExtensibleDataObject;
                        if (extensibleInstance != null)
                            extensibleInstance.ExtensionData = null;
                    }
                }
                else
                {
                    var extensibleInstance = composedInstance as IExtensibleDataObject;
                    if (extensibleInstance != null)
                        extensibleInstance.ExtensionData = null;
                }

                stream.SetLength(0);
                serializationStrategies.ComposedModelXmlSerializer.WriteObject(stream, composedInstance);
                stream.Position = 0;
                object model = serializationStrategies.BaseModelSerializer.ReadObject(stream);
                return await InputFormatterResult.SuccessAsync(model);
            }
        }
        public async override Task WriteResponseBodyAsync(OutputFormatterWriteContext context, Encoding selectedEncoding)
        {
            var serializationStrategies = DataContractSerializationStrategies.Create(context.ObjectType);

            using (var stream = new MemoryStream())
            {
                var items = context.Object as IEnumerable;
                if (items != null)
                {
                    var composedInstances = serializationStrategies.ComposedItemsCollectionFactory();
                    foreach (var item in items)
                    {
                        serializationStrategies.BaseItemXmlSerializer.WriteObject(stream, item);
                        stream.Position = 0;

                        // extra cycle to handle incorrect collection serialization
                        var composedInstance = serializationStrategies.ComposedItemXmlDeserializer.Deserialize(stream);
                        stream.SetLength(0);
                        composedInstances.Add(composedInstance);
                    }
                    stream.SetLength(0);
                    serializationStrategies.ComposedModelJsonSerializer.WriteObject(stream, composedInstances);
                }
                else
                {
                    serializationStrategies.BaseItemXmlSerializer.WriteObject(stream, context.Object);
                    stream.Position = 0;

                    // extra cycle to handle incorrect collection serialization
                    var composedInstance = serializationStrategies.ComposedItemXmlDeserializer.Deserialize(stream);
                    stream.SetLength(0);
                    serializationStrategies.ComposedModelJsonSerializer.WriteObject(stream, composedInstance);
                }

                stream.Position = 0;
                using (StreamReader reader = new StreamReader(stream))
                {
                    string json = reader.ReadToEnd();
                    await context.HttpContext.Response.WriteAsync(json, selectedEncoding);
                }
            }
        }