-
Notifications
You must be signed in to change notification settings - Fork 170
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
Feature: allow users change their property name style #359
Comments
Hi.if you choose any annotation in annotation tab in advanced config. It will generate properties' name as camelcase |
@peterstev-fm for your case, refer here : #17 |
that is the point, I do not want camelCase, I want to use snake_case in my data layer and camelCase in domain.
with with this, I would not need to annotate every field with @JSON("field_name") PS I use converter moshi. I also use mappers to map my data layer objects to the domain equivalent. so I need to be able to config the generator to use snake_case or camelCase |
Hey, is that your json is in snake_case style? If it is true, the default behavior this plugin does Will generate your data class as snake case style, And with selecting 'None(came case)' config. The data class Will generate as came case style. With these action, you could switch to snake case or camel case style. @peterstev-fm Is that enough for you? |
oh I see, it does that, but I use 'other by customize' because I want to set my class like this:
I use 'other by customize' because I want to add imports for the @JsonClass annotation for moshi, because if I select moshi directly from the options list, it adds the @JSON("field_name") which I do not want since I am using snake_case so how can I use 'other by customize' and still use snake_case. Thanks |
Got it. Currently plugin doesn't support your requst, And I want to know that why you choose snake case style, as I know it's not kotlin standard style. Does it means that your code all in snake case style? @peterstev-fm |
To achieve your requst feature, We need creat a new extension to implement it, it's not hard |
No my entire code isn't like this, I use this in the data layer of my application, so that I don't have to clutter my class with @serializedName("name") or @JSON("name") The domain layer uses camelCase, then I use mappers to map the data layer classes to the domain layer. |
Oh nice, good to know it's not hard. How soon can it be done 😁 |
So, what you want is just not use the property annotation with moshi😅? It can take several hours to implement it, But I have other tasks prefer to do, If you have interest,Hope you can do it by yourself, it's easy. Refer here: src/main/kotlin/extensions/yuan/varenyzc/CamelCaseSupport.kt Write one class like that(we may named it as let all property' name to be snake case style) and add it into here is ok 'src/main/kotlin/extensions/ExtensionsCollector.kt' That's all need to be done |
Okay I've seen the CamelCaseSupport file, I'll build the feature and create a PR. That's good? |
Good! Very good!😄 |
Allow users to determine what style they want their property naming to follow.
Camel case
raw json property names (as is)
maybe both camelCase and raw types if possible
for example I want my class properties to be defined as
instead of
so I do not have to explicitly change every generated property name to suite my style, because if I have to do all that I might as well define the class manually myself.
The text was updated successfully, but these errors were encountered: