Refers to data classes feature in Kotlin programming language.
Questions tagged [data-class]
380 questions
0
votes
1 answer
Initialise data class object to 1 or 2 arguements in kotlin?
I have the below data class
data class ApiPost(
@SerializedName("LoginId") var userName: String,
@SerializedName("Password") var password: String,
@SerializedName("NewPassword") var newPassword: String,
@SerializedName("FileType") var FileType:…

WISHY
- 11,067
- 25
- 105
- 197
0
votes
2 answers
How to initialise 'MutableMap' from constructor of data class in kotlin?
I have a data class which has a constructor like this (source):
data class MyDataClass (
val myArr: ArrayList
) {
constructor(n: Int):
this(
ArrayList((0 until n).map { ('A' + it).toChar() })
)
}
As an…

Akshdeep Singh
- 1,301
- 1
- 19
- 34
0
votes
1 answer
How to set values to data class if some size is specified in kotlin?
I have a data class in kotlin like this:
data class myDataClass(val myArr: ArrayList)
Now, suppose I create an instance of it as follows:
val myData = myDataClass(x) // x is an integer; 1 <= x <= 9
I want that myData should have the…

Akshdeep Singh
- 1,301
- 1
- 19
- 34
0
votes
1 answer
Override a val in data class
I got an error of java.lang.StackOverflowError: stack size 8MB when I tried this bit of code and the app crashed exactly 1 time and now it doesn't crash again, I would like to find out if this would cause any problems in the future before committing…

Mahmoud Omara
- 533
- 6
- 22
0
votes
1 answer
Parsing JSON String with data classes
After running the following line of code trying to pass a JSON string:
var test = String(tempstore, Charset.forName("US-ASCII"))
var gson = Gson()
var testmodel = gson.fromJson(test, AuthoriseReq::class.java)
The JSON…

George
- 2,865
- 6
- 35
- 59
0
votes
1 answer
Any data type not working in data class kotlin
I just started to learn kotlin.
This is my data class.
data class UserModel(
@SerializedName("Id")
val id: Int = 0,
@SerializedName("myKey")
val myKey: Boolean? = false
//var myKey: Any?
While I use simple as val myKey:…
user6043117
0
votes
0 answers
Only concrete Realm classes are allowed in RealmLists. Neither interfaces nor abstract classes are allowed
I am trying to convert my kotlin-data-class into Realm supported model class but getting the above error.
I have followed this below link to convert my data class into realm supported class
Kotlin data class of RealmObject
This error has come…

B.shruti
- 1,589
- 1
- 21
- 41
0
votes
3 answers
How to save old data in a data class in Kotlin
I am trying to use a data class but I can't figure out how to save the data properly.
I have created a data class:
data class SavedValue( var currentValue:String, var previousValue:String = "")
What I want is each time I am want to save a new…

Seb
- 2,929
- 4
- 30
- 73
0
votes
1 answer
Creating new instance of Kotlin data class with sorted inner data class
I have a Kotlin data class called ParcelBoxByID.kt and at one point I need to remove some Locker's from the ParcelBoxByID.kt data class.
As an input I get one instance of ParcelBoxByID.kt and I need to get back the same ParcelBoxByID.kt, but with…

Richard
- 1,087
- 18
- 52
0
votes
1 answer
Parsing JsonObject into kotlin Data class
I am fairly new to Kotlin and I am trying to parse the JsonObject that I get from my HTTPRequest into data class. But I cannot get the Instance from the data class.
val jsonObjectRequest = JsonObjectRequest(Request.Method.GET, url, null,
…

Richard
- 1,087
- 18
- 52
0
votes
1 answer
Returning a custom type
I have access to a library, but I don't want to fork the code and maintain the library, because I am too new to Kotlin.
The code looks like this:
data class Foo(val foos: ..., bars: ...)
I can call methods from the library to get back a…

Bah
- 1
0
votes
2 answers
Transform data class to map kotlin
My problem is that I need to transform a data class in kotlin to a map, because I need to work with this structure as a requirement, because this response will be used for a groovy classes and there is a post-process where there are validations…

rasilvap
- 1,771
- 3
- 31
- 70
0
votes
3 answers
Boolean turns into int number 904 in Kotlin
I'm working on a quiz app for my project at university, and I'm trying to save button and boolean that states if the answer is correct or not in data class and save all buttons in a temporary list so I can add onclick listener for all of them later.…

Tukanoid
- 81
- 2
- 3
- 10
0
votes
2 answers
Kotlin Data class copy extension
I am trying to find a solution for a nice kotlin data class solution. I have already this:
data class Object(
var classMember: Boolean,
var otherClassMember: Boolean,
var example: Int = 0) {
fun set(block: Object.() -> kotlin.Unit):…

davidOhara
- 1,008
- 5
- 17
- 39
0
votes
1 answer
Room: query with subquery. How to model the dataclasses?
I would like to perform a query on a room database that results in a list of records, which are composed of columns from several tables. First I have a subquery which is then joined with another table. In the result I select only a few columns. In…

Raoul
- 101
- 9