Search code examples
breeze

How to get Metadata for camelCase JsonFormatter


I am using the following in my Global.asax to change the formatting to camelCase on the client.

        // Change Json data to camelCasing
        var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
        json.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

In addition, we are using Unity, and I have a Separate Service and a custom EFContextProvider class that resturns metadata, consumed in the Controller. I assume that because I'm generating Metadata outside of the BreezeController, it then is returning the metadata in PascalCase, which my Code first DbContext is all using.

End result is that I get PascalCased Metadata(this seems incorrect from waht I expect) and camelCased entities from entityQueries but are not observable knockout properties. Any tip or ideas why my entities are not observable would be appreciated.


Solution

  • You don't need to use a ContractResolver for this, Breeze handles this directly via it's NamingConvention class: See the NamingConvention discussion on this page. Breeze Docs - NamingConvention.

    Basically, all you need to do is call:

     breeze.NamingConvention.camelCase.setAsDefault(); // a convention can self-register as the default