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

[Feature Request]Suffix appending behind of all class name #165

Closed
Hades32 opened this issue Apr 24, 2019 · 6 comments
Closed

[Feature Request]Suffix appending behind of all class name #165

Hades32 opened this issue Apr 24, 2019 · 6 comments

Comments

@Hades32
Copy link

Hades32 commented Apr 24, 2019

Example json:

{
"Master":{
  "a":1
  }
}

When using inner classes will generate a inner class and a field named Mater.

data class Blubber(
    val Master: Master?
) {
    data class Master(
        val a: Int?
    )
}

Easiest fix would be to append some postfix like ...Data.

@kezhenxu94
Copy link
Collaborator

Hi @Hades32 I think making the first letter lowercase is better, what do you think? could you send a pull request to fix this? thanks

Sent from mini-github

@wuseal
Copy link
Owner

wuseal commented Apr 25, 2019

@Hades32 Try to select an annotation or use the suffix function:
image

  • By this method, all properties name will be renamed to lower camelcase, like val master: Master?

image

  • By this method, all properties name will append with a Data postfix, like val MasterData: Master?

If there any problem, Please contact us, thanks.

@Hades32
Copy link
Author

Hades32 commented Apr 25, 2019

@wuseal both solution have issues: annotations make the code less portable and a suffix breaks compatibility with the actual json which is not under my control.

I'd prefer if there were an extension "Suffix after every class name". Then I'd just enter "Dto" and all the classes would be Dtos

@wuseal
Copy link
Owner

wuseal commented Apr 25, 2019

@Hades32, Yeah, An extension could implement your request feature, And the implemented code may be like this in extension instance class :

    override fun intercept(kotlinDataClass: KotlinDataClass): KotlinDataClass {

        val standTypes = listOf<String>("Int", "Double", "Long", "String", "Boolean")
        val originName = kotlinDataClass.name
        val newPropertyTypes =
            kotlinDataClass.properties.map { if (standTypes.contains(it.type)) it.type else it.type + "Dto" }

        val newProperties = kotlinDataClass.properties.mapIndexed { index, property ->

            val newType = newPropertyTypes[index]

            property.copy(type = newType)
        }
        return kotlinDataClass.copy(name = originName + "Dto", properties = newProperties)
    }

And If you interested in this, A PR for this feature will heighly appreciated.
You could refer to Extensions for building this feature.
For the code like upon, the code could be generated like this:

data class BlubberDto(
    val Master: MasterDto
)

data class MasterDto(
    val a: Int 
)

@sealkingking sealkingking changed the title Conflict between Class name and Field name when using inner classes and field names are capitalized [Feature Request]Suffix appending behind of all class name Apr 29, 2019
@wuseal wuseal added this to the 3.3.0 milestone May 9, 2019
@smilechenbiao
Copy link
Contributor

I have added this function,You can use it in later new versions.

@wuseal wuseal modified the milestones: 3.3.0, 3.4.0 Jun 17, 2019
@wuseal wuseal modified the milestones: 3.4.0, 3.3.0 Jun 24, 2019
@wuseal
Copy link
Owner

wuseal commented Jun 24, 2019

Fixed in 3.3.0-EAP-2

@wuseal wuseal closed this as completed Jun 24, 2019
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