joukevandermaas / saule

JSON API library for ASP.Net Web API 2.
https://joukevandermaas.github.io/saule
MIT License
76 stars 37 forks source link

option to serialize attributes in camelCase #190

Closed barsh closed 6 years ago

barsh commented 6 years ago

This PR resolves closes #188.

This PR includes an option to serialize/deserialize attributes as camelCase instead of kebab/dash notation.

public static void Register(HttpConfiguration config)
{
    // ...

    var jsonApiConfig = new JsonApiConfiguration
    {
        PropertyNameConverter = new CamelCasePropertyNameConverter()
    };
    config.ConfigureJsonApi(jsonApiConfig);

    // ...
}
barsh commented 6 years ago

@joukevandermaas I'll do some more work on this over the weekend. Have you considered creating a Gitter for this repo? It's a nice way for consumers and contributors to collaborate on open source projects. Here's a Gitter for a json api repo for rails.

joukevandermaas commented 6 years ago

@barsh I had not considered it, but I'm definitely open to it. Thanks for the suggestion, I'll take a look.

barsh commented 6 years ago

@joukevandermaas my original goal for this PR was to allow attributes be renamed like this:

Attribute(nameof(Person.FirstName), renameAs: "firstName")

I realized significant effort would be required to make that work, because sorting and filtering does not work if you rename an attribute to something other than the camelCase, PascalCase, or kebab-case equivalent of the original attribute name.

So I have reworked this PR for the purpose of providing an option to serialize attributes with camelCase. I revised my opening comment to match this change of mindset.

I'm submitting this for reivew, bc I think my work is done here.

barsh commented 6 years ago

@joukevandermaas this PR is ready for review, including documentation and unit tests.

barsh commented 6 years ago

@joukevandermaas my last commit should address the backwards compatibility issues. Let me know if you see anything else.