How do I make a data class as an ArrayList in another data class?

824 Views Asked by At

This is my data class.

@Entity
@Table(name = "loan_category")
data class Loan_category (

    @Id
    @Column(name = "loan_id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    val id: Long? = null,

    @Column(name = "category_name",unique = true,nullable = false)
    val categoryName : String = "",

    @Column(name = "interest_rate")
    val interest_rate : Float = 0.0F,

    @Column(name = "overdue_interest")
    val overdue_interest : Float = 0.0F,

    @Column(name = "overdue_period")
    val overdue_period : String = "",

    @Column(name = "minSurety")
    val minSurety:Int = 0,

    @Column(name = "totaline")
    val totalFine: Float = 0.0F
)

I want to declare this data class like an ArrayList in another entity. How can it be done?

1

There are 1 best solutions below

2
On

If I understood correctly, you want to have a list of this data class, in another data class?

data class Loan(
    @SerializedName("loan_categories")
    val categories: List<LoanCategory>
)

And you would instantiate it as

Loan(emptyList())