398 questions
1
vote
2
answers
131
views
How to represent the changes to an instance of a data class (diff)?
I maintain an application which helps users to track the progress of an activity in real time. In essence, we represent the state of said activity as a data class in the Android mobile app. Every time ...
2
votes
1
answer
62
views
Kotlin data class with default constructor parameter
I want to use a data class with a property that has a default value in the constructor based on another constructor parameter. It works exactly as I want it if I use a normal (non-data) class:
import ...
1
vote
1
answer
111
views
Is it problematic to derive a default value of a member from other members in a data class?
I have a data class like this:
data class Calculation(
val calculationType: String = "Multiplication", // or "Division"
val firstOperand: Int,
val secondOperand: Int,
...
0
votes
3
answers
133
views
How to make data class copy with only properties initialized, to avoid StackOverflowError?
I have encountered a problem while trying to resolve problem with sensitive info in application logs — we have quite large data class object that at some time in processing flow we log. Problem is ...
-1
votes
1
answer
448
views
dataclasses for ORM models in SQLAlchemy
I am trying to define a dataclass for my model in the same class of the model, where i have defined the table.
this is my model class,
from dataclasses import dataclass, field
from sqlalchemy import ...
1
vote
2
answers
241
views
Pydanyic V2: how to write more intelligent `created_at`, `updated_at` fields
I wanna write a nice TimestampMixin class for my project, I hope it can:
created_at: autonow when creation, and never change since that
updated_at: autonow when creation
updated_at: auto update ...
1
vote
0
answers
27
views
Getting right order of `declaredMemberProperties` in a `listOf<Any>` [duplicate]
Edit: The "already answered answer" doesn't get me the values of the data class object. I can only access the field name and the order id, but NOT the value (here "0", "A"...
0
votes
1
answer
74
views
Why do changes to a list alter another list within ViewModel, too?
I have an ArrayList
val tasks = remember { mutableStateListOf<TaskItem>() }
where the TaskItem is
@Keep
@Parcelize
data class Task(
var task: String,
var done: Boolean = false
) : ...
1
vote
1
answer
112
views
Aggregate initialization with struct copy construction
Is there a way of mimicking Kotlin's data class 'copy()' in C++ ?
This allows copying the object and modify specific parts of it within a single expression, see Kotlin example:
data class SomeData(val ...
-1
votes
1
answer
203
views
String Casting to Data Class with Kotlin
I have data class. I have inserting the room database this data class. it has string type. But I want to use back. I have calling the data. It has string. But I want to convert the data class type.
...
0
votes
2
answers
796
views
I want to use get set method in field of data class kotlin
data class Thermostat(
// ... other properties
@SerializedName("units")
private var _units: String?, // Fahrenheit,
// ... other properties
) : Serializable {
var units:...
-1
votes
1
answer
262
views
DataClasses in Kotlin - Overriding the equals() from 'Any' Class
I've been working on overriding the equals() from Any class. But in the below code. I'm confused why
"if (other is Person)" is necessary to get the "if(this.firstName == other.firstName)...
4
votes
2
answers
3k
views
Why doesn't Kotlin implicitly assign null values nullable fields in a data class constructor?
Given a data class with a nullable field, why can't I construct it by only passing the non-nullable fields ?
I have already seen this related question. What is preventing Kotlin from implicitly ...
0
votes
0
answers
141
views
Ignore exclude variable in equals in data class Kotlin
Is there a way like transient keyword in kotlin that will equals all other attribute except a boolen var
As I have numerous attributes,I thought there must be a keyword for it.
Product.kt
@Parcelize
...
0
votes
1
answer
540
views
Omit optional parameters set as null in Kotlin data class
Best practice to omit optional parameter in a data class when its assigned null?
Example: data class xyz(val a:String ?,val b: String?, val c: String?= null)
if c = null, then data class xyz(val a:...
0
votes
1
answer
66
views
Flutter dataclass for GraphQL response - value can be another class or null
I am currently developing an app in Dart/Flutter and I am facing one issue with my data class to handle my GraphQL response.
My User class is defined as following:
import 'package:json_annotation/...
1
vote
1
answer
735
views
How to Represent a Union Type in Dart Similar to TypeScript for Creating a Data Class with json_serializable?
I am currently working on a Flutter project where I am trying to create a data class for a User that involves an Image property. In TypeScript, I have a union type Image that can be either a boolean ...
0
votes
2
answers
268
views
Error: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $ - RxJava
I am calling an API using RxJava and Retrofit and storing the data in data class of kotlin. While calling the api, an error is thrown : java.lang.IllegalStateException: Expected BEGIN_ARRAY but was ...
0
votes
1
answer
847
views
How to access the values of a data class in Kotlin?
Here's the codes that is working:
data class Abc(
val a: String,
val b: String,
val c: String,
val d: D
) {
data class D(
val e: String,
val f: String,
val ...
-1
votes
1
answer
423
views
What is the best way to add information to a data class returned by a function without breaking existing code? [closed]
Here is my code::
data class User(val id: Int, name: String)
fun getUsers(): List<User>
Now, I want to add an age field to the User data class, but I'm concerned about two things:
Breaking the ...
1
vote
1
answer
151
views
keyNotFound Swift Alamofire [duplicate]
Model Class
public struct Products : Codable {
let data: [ProductData]
let error: Bool
let message: String
}
public struct ProductData : Codable {
let id, category, subCategory, name, ...
2
votes
1
answer
1k
views
Are Kotlin data classes Value types or Reference type?
I am from Swift background. Swift has both "value" type & "reference" type support, I am bit curious. Does Kotlin have similar concepts?
By default, any class is a reference ...
1
vote
1
answer
44
views
How should I manage data classes of various subtypes?
This is my problem, imagine you need to show a table of clients, there you only need to show about 4 fields of the data class Client:
Name
Last Name
Birthday
Id
But when I go to the details of a ...
2
votes
0
answers
2k
views
Writing Spring boot's entities with kotlin, class vs data class for JPA
I would like to understand the best practices in creating Kotlin entities with JPA.
First, this is a part of my build.gradle.kts. I have added both plugin.jpa and plugin.allopen
plugins {
id("...
0
votes
0
answers
1k
views
kotlin, spring boot and data classes for configuration
I've implemented several projects with spring boot and java. Now I'm evaluating, if I could do it with kotlin.
I am struggling with @ConfigurationProperties and data classes.
Simple example:
api:
...