Skip to content

SimklApi: migrate to kotlinx serialization#2998

Open
Luna712 wants to merge 1 commit into
recloudstream:masterfrom
Luna712:migrate30
Open

SimklApi: migrate to kotlinx serialization#2998
Luna712 wants to merge 1 commit into
recloudstream:masterfrom
Luna712:migrate30

Conversation

@Luna712

@Luna712 Luna712 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

This has some extra affects that required a little more changes than the other migrations did:

First, MediaObject was an open base class shared via inheritance by HistoryMediaObject/RatingMediaObject/StatusMediaObject. kotlinx doesn't walk inherited properties the way Jackson does:

  • A super class requires either SerialName or @Transient
  • A sub class can not have the same @SerialName as the super class due to JSON conflict
  • That would mean, the super class would need @Transient which works for abstract but not really open classes, because an open class may be used standalone also, and @Transient prevents that particular field from being what triggers serialization, which means without a sub class it wouldn't work at all.

Therefore, to resolve this issue, I switched to flat, independent data classes (composition instead of inheritance), and split StatusRequest into StatusRequest/HistoryRequest so each request body is typed to its concrete element type.

Also, this new way makes the code a little more explicitly and easier to understand IMO anyway.


Secondly, SimklCacheWrapper<T> was generic, but kotlinx needs a concrete serializer per type, which generics erase at runtime. Therefore for me to resolve this, I replaced it with two concrete wrapper classes (MediaObjectCacheEntry and EpisodesCacheEntry) since those were the only two things ever cached, plus a small CacheFreshness class for the generic "check any entry's expiry".


I did also fully test this but I suppose there is a possibility I could have missed something.

This has some extra affects that required a little more changes than the other migrations did:

First, `MediaObject` was an open base class shared via inheritance by `HistoryMediaObject`/`RatingMediaObject`/`StatusMediaObject`. kotlinx doesn't walk inherited properties the way Jackson does:
* A super class requires either `SerialName` or `@Transient`
* A sub class can not have the same `@SerialName` as the super class due to JSON conflict
* That would mean, the super class would need `@Transient` which works for abstract but not really open classes, because an open class may be used standalone also, and `@Transient` prevents that particular field from being what triggers serialization, which means without a sub class it wouldn't work at all.

Therefore, to resolve this issue, I switched to flat, independent data classes (composition instead of inheritance), and split `StatusRequest` into `StatusRequest`/`HistoryRequest` so each request body is typed to its concrete element type.

Also, this new way makes the code a little more explicitly and easier to understand IMO anyway.

----

Secondly, `SimklCacheWrapper<T>` was generic, but kotlinx needs a concrete serializer per type, which generics erase at runtime. Therefore for me to resolve this, I replaced it with two concrete wrapper classes (`MediaObjectCacheEntry` and `EpisodesCacheEntry`) since those were the only two things ever cached, plus a small `CacheFreshness` class for the generic "check any entry's expiry".

----

I did also fully test this but I suppose there is a possibility I could have missed something.
@Luna712

Luna712 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

/run-tests

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Instrumented tests are running. View live progress

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Instrumented tests passed. View results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant