I'm currently working on a Kotlin Wrapper for Gitl...
# getting-started
e
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
Have a common
sealed interface
with 2 classes inheriting from it
e
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
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
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