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

Add naming strategy support when post/put.. an object by url-encoded #912

Open
litliang-cn opened this issue Apr 23, 2020 · 4 comments
Open

Comments

@litliang-cn
Copy link

litliang-cn commented Apr 23, 2020

Is your feature request related to a problem? Please describe.

When calling Java's rest API (post/put.. an object by url-encoded), we have to add [AliasAs] attribute to each property of the class due to the difference of naming strategy (Java uses Camel, C-Sharp generally uses Pascal). It's a little silly.

Describe the solution you'd like

Can we increase the transformation of naming strategy (like newtonsoft. JSON), or provide an extension interface for us to implement the transformation from object to formdata?
Thanks!!

Describe alternatives you've considered

Maybe you can take 'BodySerializationMethod' as a parameter of 'IcontentSerializer.SerializeAsync' method, and then use newtonsoft.json to complete the transformation of naming strategy (convert object to JObject, and then traverse the properties of JObject)

Describe suggestions on how to achieve the feature

Additional context

@bennor
Copy link
Contributor

bennor commented Apr 23, 2020

Refit just uses Json.NET under the hood, so you can do this already. There's even an example in the README: https://github.com/reactiveui/refit#json-content

(Look for CamelCasePropertyNamesContractResolver.)

GitHub
The automatic type-safe REST library for .NET Core, Xamarin and .NET. Heavily inspired by Square's Retrofit library, Refit turns your REST API into a live interface. - reactiveui/refit

@bennor bennor closed this as completed Apr 23, 2020
@litliang-cn
Copy link
Author

it does not wor when post form data(Body attribute was initialized with BodySerializationMethod.UrlEncoded) @bennor

@bennor
Copy link
Contributor

bennor commented Apr 24, 2020

Ah, apologies. I missed that part of the description.

@bennor bennor reopened this Apr 24, 2020
@xljiulang
Copy link
Contributor

Maybe only WebApiClient can help you!

services.AddHttpApi<IUserApi>(o =>
{
    // o.KeyValueSerializeOptions.PropertyNamingPolicy = null;
    o.KeyValueSerializeOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants