JsonToKotlinClass icon indicating copy to clipboard operation
JsonToKotlinClass copied to clipboard

Enable Default Constructor Creation Option

Open Danc2050 opened this issue 2 years ago • 1 comments

In the case when we want to send a class out as a Request, it would be useful to create a constructor with default arguments in some cases, which we could change later. For example, see constructor() at the bottom of this code:

data class Activity(
    var updated_on: String,
    var tags: List<String>,
    var description: String,
    var user_id: List<Int>,
    var status_id: Int,
    var title: String,
    var created_at: String,
    var data: HashMap<*, *>,
    var id: Int,
    var counts: LinkedTreeMap<*, *>
) {
    constructor() : this("", emptyList(), 
                         "", emptyList(), -1, 
                         "", "", hashMapOf<Any, Any>(), 
                         -1, LinkedTreeMap<Any, Any>()
                         )
}

Danc2050 avatar Nov 30 '22 05:11 Danc2050

Enable init with default value option in settings and then it will generate data class with init value, the effect is the same as your descriptions

When data class all fields initial with default value it will auto has a default construct that no need pass parameters when new a data class object

wuseal avatar Nov 30 '22 17:11 wuseal