Stijndcl
12/17/2024, 9:13 PM@Serializable
data class Item(val id: Int, val client: ApiClient)
In the quick example above I'd want the ID to be deserialized from the payload, but somehow need a way to pass in the ApiClient myself. Placed it as a constructor param as an example but it doesn't have to be.
Creating a nullable @Transient
property and manually filling in the field after each deserialization is possible I guess but really ugly imo and I'd rather avoid it. Was hoping there's a better way here?Daniel Pitts
12/17/2024, 10:09 PMStijndcl
12/18/2024, 12:27 PMItem.method()
and Item1.method(Item2)
are both a lot nicer to work with from a user-perspective than ApiClient.item_method(Item1, Item2)
Daniel Pitts
12/18/2024, 3:22 PMStijndcl
12/18/2024, 3:53 PMDaniel Pitts
12/18/2024, 5:26 PMclass MyWrapper(val service: MyService, val data: MyData) {
fun doTheThing(): MyOtherWrapper {
val otherData: MyOtherData = service.doTheThing(data)
return MyOtherWrapper(service, otherData)
}
}
Stijndcl
12/18/2024, 5:27 PMDaniel Pitts
12/18/2024, 5:28 PMStijndcl
12/18/2024, 5:29 PMDaniel Pitts
12/18/2024, 5:29 PMDaniel Pitts
12/18/2024, 5:30 PMDaniel Pitts
12/18/2024, 5:31 PMStijndcl
12/18/2024, 5:32 PMStijndcl
12/18/2024, 5:33 PMdata class MyData(val someField)
// Usage
SomeService/Client.someMethod(someObject)
println(someObject.someField)
with your thing this would be
someObject.someMethod()
println(someObject.data.someField)
which defeats the purpose entirely, it's not a shortcut as it moved the extra fluff to attributes instead of methodsDaniel Pitts
12/18/2024, 5:34 PMStijndcl
12/18/2024, 5:34 PMDaniel Pitts
12/18/2024, 5:35 PMStijndcl
12/18/2024, 5:35 PMDaniel Pitts
12/18/2024, 5:35 PMDaniel Pitts
12/18/2024, 5:37 PM