Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow serialization of additional properties of a non-open type #412

Closed
congysu opened this issue Jun 21, 2015 · 1 comment
Closed

Allow serialization of additional properties of a non-open type #412

congysu opened this issue Jun 21, 2015 · 1 comment
Milestone

Comments

@congysu
Copy link
Contributor

congysu commented Jun 21, 2015

Allow configure EnableFullValidation to false:

            MessageWriterSettings = new ODataMessageWriterSettings
            {
                Indent = true,
                DisableMessageStreamDisposal = true,
                MessageQuotas = new ODataMessageQuotas { MaxReceivedMessageSize = Int64.MaxValue },
                AutoComputePayloadMetadataInJson = true,
            };

https://github.com/OData/WebApi/blob/master/OData/src/System.Web.OData/OData/Formatter/ODataMediaTypeFormatter.cs#L81-L87

or Create a customer odata formatting attribute, and a custom OData controller base class:

+        [CustomODataFormatting]
+        public class CustomODataController : ODataController
+        {
+        }
+
+        [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
+        public class CustomODataFormattingAttribute : Attribute, IControllerConfiguration
+        {
+            public void Initialize(HttpControllerSettings controllerSettings,
+                HttpControllerDescriptor controllerDescriptor)
+            {
+                Func<IList<ODataMediaTypeFormatter>> getODataFormatters =
+                    () => controllerSettings.Formatters.OfType<ODataMediaTypeFormatter>().ToList();
+
+                var odataFormatters = getODataFormatters();
+                if (!odataFormatters.Any())
+                {
+                    new ODataFormattingAttribute().Initialize(controllerSettings, controllerDescriptor);
+                    odataFormatters = getODataFormatters();
+                }
+
+                foreach (var formatter in odataFormatters)
+                {
+                    formatter.MessageWriterSettings.EnableFullValidation = false;
+                }

Related ODataLib issue: OData/odata.net#179

@congysu
Copy link
Contributor Author

congysu commented Jun 24, 2015

@hotchandanisagar @gkasturi Can we know your option on the issue?

@congysu congysu added this to the v5.9 milestone Dec 1, 2015
@VikingsFan VikingsFan modified the milestones: v5.10, v5.9 Mar 21, 2016
@robward-ms robward-ms added the P4 label Jun 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants