wuseal/JsonToKotlinClass

Null initialization option

cgoodroe opened this issue ยท 7 comments

Hi @wuseal , what do you think about an option to initialize all objects as null? I've found that I often need this functionality.

@SerializedName("MyObject") var myObject: MyObject? = null

Also, sorry I'm very busy, I'll test those other issues when I have more time, thanks!

@cgoodroe Thanks for your usage feedback and your valuable time ,Yes ,That's a good idea. because json string is not reliable ,Some time its value maybe null or empty ,I also think there is need to have the option as you said ^_^ ,But when the type is Int,Double,Boolean .ect which can have a default value,Do we need them to be null as the initialize value?

@wuseal good question... I think default value in those cases is probably best, but I'm not 100% sure, what do you think?

@cgoodroe I think Just add character '?' after each property type without null init value would be ok.
What the real situation that u want them to be init with null value?

@wuseal I think you're right, maybe null is always wrong. Can we make the option to always use default values? Maybe something like:

var myObject: MyObject = MyObject()
var myInt: Int = 0
var myString: String = ""
var myList: List<MyObject> = listOf()

I'm not sure what's best for list, I'm still new to Kotlin... there's others like arrayListOf() and mutableListOf(), etc... I'll leave it up to you!

What do you think?

Yes !,That's a good idea .We will make it come to out soon

@cgoodroe Hi,New version has been released ,the list default value has been set to 'listOf()',I think it's OK,The init with default value option has been added ,and also added an option to switch whether the property type to be nullable.
If you have time ,you can update to 1.3 to have a test ,If all works well ,then you could close this issue.
Thanks for your issues again ^_^.

Close this issue now ,if have any issue ,you can raise a new issue or reopen this issue