SimklApi: migrate to kotlinx serialization#2998
Open
Luna712 wants to merge 1 commit into
Open
Conversation
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.
Contributor
Author
|
/run-tests |
|
Instrumented tests are running. View live progress |
|
Instrumented tests passed. View results |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This has some extra affects that required a little more changes than the other migrations did:
First,
MediaObjectwas an open base class shared via inheritance byHistoryMediaObject/RatingMediaObject/StatusMediaObject. kotlinx doesn't walk inherited properties the way Jackson does:SerialNameor@Transient@SerialNameas the super class due to JSON conflict@Transientwhich works for abstract but not really open classes, because an open class may be used standalone also, and@Transientprevents 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
StatusRequestintoStatusRequest/HistoryRequestso 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 (MediaObjectCacheEntryandEpisodesCacheEntry) since those were the only two things ever cached, plus a smallCacheFreshnessclass 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.