I'm currently working on a Kotlin Wrapper for Gitlab. They have this api endpoint, which depending on a request parameter either returns a list of detailed or simple projects. I'm struggling to find the best way to model this for KotlinX Serialization. Of course I could make it completely distinct types, but that honestly seems a bit lazy, as they still are somewhat related and I wanna keep that relationship. Any tips or ideas on how to model this best?
https://docs.gitlab.com/api/projects/#list-all-projects
y
Youssef Shoaib [MOD]
03/07/2025, 1:41 PM
Have a common
sealed interface
with 2 classes inheriting from it
e
Eve Kolb
03/07/2025, 1:42 PM
And that interface should contain the fields from the Simple Project, which is a subset of the fields from the detailed project, right?
✔️ 2
m
MarkRS
03/07/2025, 2:11 PM
Doesn't that mean it would be better to have a "base class" that implements the simple case and then a "complex class" that inherits from it with the required extras?
c
CLOVIS
03/09/2025, 12:47 PM
IMO,
• either have all additional fields as nullable, but that's going to be painful if you use them a lot,
• or have an interface for common fields, and two methods, one returning the base case, and the other returning the extended case