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

Generated model not matching JSON #241

Closed
ColtonIdle opened this issue Sep 13, 2019 · 10 comments
Closed

Generated model not matching JSON #241

ColtonIdle opened this issue Sep 13, 2019 · 10 comments
Assignees
Milestone

Comments

@ColtonIdle
Copy link

My input:

{
	"generic": [{
			"name": {
				"address": "123"
			},
			"call_me": "ONE"
		},
		{
			"name": {
				"address_secondary": "GO TO ACCOUNT"
			},
			"call_me": "TWO"
		},
		{
			"name": {
				"address_present": false
			},
			"call_me": "THREE"
		},
		{
			"name": {
				"none": "Bill",
				"sure": "Gates"
			},
			"call_me": "FOUR"
		}
	]
}

Actual output:

data class Output(
    val generic: List<Generic> = listOf()
) {
    data class Generic(
        val call_me: String = "",
        val name: Name = Name()
    ) {
        data class Name(
            val none: String = "",
            val sure: String = ""
        )
    }
}

Expecting something along the lines of:

data class Output(
    val generic: List<Generic> = listOf()
) {
    data class Generic(
        val call_me: String = "",
        val name: Name = Name()
    ) {
        data class Name(
            val address: String = "",
            val address_secondary: String = "",
            val address_present: String = "",
            val none: String = "",
            val sure: String = ""
        )
    }
}
@wuseal wuseal added this to the 3.6.0 milestone Sep 16, 2019
@wuseal
Copy link
Owner

wuseal commented Sep 16, 2019

@ColtonIdle Got, It will be fixed in next version, Thanks for your feedback 😄

@ColtonIdle
Copy link
Author

Is there anything I can do to help? This is preventing me from using this plugin for the past few months.

@wuseal can you reproduce?

@wuseal
Copy link
Owner

wuseal commented Feb 26, 2020

@ColtonIdle Yes, I had reproduced it. if possible, can you help to resolve this problem in branch 3.6.0-dev?

@wuseal wuseal self-assigned this Feb 26, 2020
@ColtonIdle
Copy link
Author

@wuseal How can I try the 3.6.0-dev branch? I use the plugin in Android Studio.

@wuseal
Copy link
Owner

wuseal commented Feb 26, 2020

At first you need pull down this project code and switch to branch 3.6.0-dev, then You could build the plugin zip follow the steps describe in README
https://github.com/wuseal/JsonToKotlinClass#build-from-source

@ColtonIdle
Copy link
Author

ColtonIdle commented Feb 27, 2020

Still broken

3.6.0-dev

My input:

{
	"generic": [{
			"name": {
				"address": "123"
			},
			"call_me": "ONE"
		},
		{
			"name": {
				"address_secondary": "GO TO ACCOUNT"
			},
			"call_me": "TWO"
		},
		{
			"name": {
				"address_present": false
			},
			"call_me": "THREE"
		},
		{
			"name": {
				"none": "Bill",
				"sure": "Gates"
			},
			"call_me": "FOUR"
		}
	]
}

Actual output:

data class Output(
    val generic: List<Generic> = listOf()
) {
    data class Generic(
        val name: Name = Name(),
        val call_me: String = ""
    ) {
        data class Name(
            val none: String = "",
            val sure: String = ""
        )
    }
}

Expecting something along the lines of:

data class Output(
    val generic: List<Generic> = listOf()
) {
    data class Generic(
        val call_me: String = "",
        val name: Name = Name()
    ) {
        data class Name(
            val address: String = "",
            val address_secondary: String = "",
            val address_present: String = "",
            val none: String = "",
            val sure: String = ""
        )
    }
}

@wuseal
Copy link
Owner

wuseal commented Mar 5, 2020

The expected result should be like this, all right?

data class Output(
    val generic: List<Generic> = listOf()
) {
    data class Generic(
        val name: Name = Name(),
        val call_me: String = ""
    ) {
        data class Name(
            val address: String = "",
            val address_secondary: String = "",
            val address_present: Boolean = false,
            val none: String = "",
            val sure: String = ""
        )
    }
}

I have fixed this issue in branch dev_3.6.0/bugfix/#241, you could have a try if it works for you.

wuseal added a commit that referenced this issue Mar 5, 2020
@wuseal wuseal added bug fixed but not released this issue has been solved but is not released yet labels Mar 5, 2020
@ColtonIdle
Copy link
Author

Yes, that's the expected result. @wuseal do you think the result should be different?

I will check out the branch later today.

@wuseal
Copy link
Owner

wuseal commented Mar 5, 2020

please try branch 3.6.0-dev for pre said branch has been removed

@ColtonIdle
Copy link
Author

It worked! 🙏

This fixes so many issues of mine since one of my backends on a project omits null values, and so they don't come across the wire, but this plugin was completely erasing it from the model.

data class Output(
    val generic: List<Generic> = listOf()
) {
    data class Generic(
        val name: Name = Name(),
        val call_me: String = ""
    ) {
        data class Name(
            val address: String = "",
            val address_secondary: String = "",
            val address_present: Boolean = false,
            val none: String = "",
            val sure: String = ""
        )
    }
}

Thank you @wuseal !

@wuseal wuseal closed this as completed in 50c2825 Mar 19, 2020
@wuseal wuseal removed the fixed but not released this issue has been solved but is not released yet label Mar 21, 2020
wuseal pushed a commit that referenced this issue Sep 20, 2021
wuseal added a commit that referenced this issue Sep 20, 2021
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

2 participants