wuseal / JsonToKotlinClass

🚀 Plugin for Android Studio And IntelliJ Idea to generate Kotlin data class code from JSON text ( Json to Kotlin )

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parcelable support

amorenew opened this issue · comments

I wonder If you could add Parcelable support to the data class
like below

@Parcelize
data class DataResponse(
        @SerializedName("Isvalid") var isValid: Boolean,
) : Parcelable
commented

@amorenew Hi, Now it could support adding @Parcelize annotation on the class by custom annotation option, But can't support parent class declaration, The parent class declaration will be supported next version soon. Good advice!

commented

@amorenew Hi, An EAP version has just released, And it could fix this issue, Have a try if it works for you.

First update the settings like this:

image
image

And then you could generate class code like this:

import android.os.Parcelable
import kotlinx.android.parcel.Parcelize

@Parcelize
data class Data(
        val feedbacks: Feedbacks = Feedbacks(),
        val liketeamlist: List<Liketeamlist> = listOf(),
        val partnerteamlist: List<Partnerteamlist> = listOf()
) : Parcelable {
    @Parcelize
    data class Feedbacks(
            val feedbacklist: List<Feedbacklist> = listOf(),
            val totalcount: Int = 0, // 1
            val totalscore: Int = 0 // 5
    ) : Parcelable {
        @Parcelize
        data class Feedbacklist(
                val comment: String = "", // 5分
                val createtime: String = "", // 2016.09.07 12:38
                val score: Int = 0, // 5
                val username: String = "" // 1331##11
        ) : Parcelable
    }

    @Parcelize
    data class Partnerteamlist(
            val pteamId: Int = 0, // 716
            val pteamprice: Int = 0, // 38
            val ptitle: String = "" // 后期持续更新!
    ) : Parcelable

    @Parcelize
    data class Liketeamlist(
            val limage: String = "", // http://baidu.com/37.jpg
            val lmarketprice: Int = 0, // 3380
            val lteamId: Int = 0, // 57133
            val lteamprice: Int = 0, // 580
            val ltitle: String = "" // 测试文本,15级软件开发!
    ) : Parcelable
}

If there any question ,welcome reply me directly. Thanks.

@wuseal
Great work it is working
1-I enabled @parcelable in gradle

androidExtensions {
        experimental = true
    }

I use Gson for parsing
implementation 'com.google.code.gson:gson:2.8.5'

2- In Annotation Import class section:

import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.android.parcel.Parcelize

3- In Class Annotation Format section:
@Parcelize
4- In Property Annotation Format:
@SerializedName("%s")
5- In Parent Class Template:
android.os.Parcelable

Thanks a lot