Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properties Format: Support wrapped sealed classes #2255

Conversation

EdwarDDay
Copy link
Contributor

The properties format didn't support serialization of nested sealed classes before. This should be fixed with these changes.

@@ -102,7 +103,7 @@ public sealed class Properties(
}

final override fun <T> decodeSerializableValue(deserializer: DeserializationStrategy<T>): T {
val type = map["type"]?.toString()
val type = map[nested("type")]?.toString()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put this statement under the if condition below. Most types are not polymorphic, and here we will have an unnecessary creation of a nested key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, thank you, I changed it.

@EdwarDDay EdwarDDay force-pushed the properties_format_support_wrapped_polymorphics branch from e07f815 to fda0392 Compare April 8, 2023 05:14
@sandwwraith
Copy link
Member

Hi, thanks for the PR! Can you please elaborate on what 'wrapped' means? You used lists in test, but it seems change should work also with sealed classes contained in other classes, as in the test in here: https://github.com/Kotlin/kotlinx.serialization/pull/2262/files#diff-bec5521c216f61f12d3d730fecbe158051faf72330a89ec11de2fc6f90b85e16R54

Can you please also add this test to a test set and describe 'wrapped' in more detail in commit message? Thank you!

@EdwarDDay
Copy link
Contributor Author

EdwarDDay commented Apr 20, 2023

Yeah, I can do this. Maybe "nested" would be a better wording then "wrapped". But I just wanted to express properties (I mean properties of a class) with a sealed class type - or in the case of lists or maps it would be the sealed class type as the type parameter.

@EdwarDDay EdwarDDay force-pushed the properties_format_support_wrapped_polymorphics branch from fda0392 to 794989e Compare April 20, 2023 17:26
Copy link
Member

@sandwwraith sandwwraith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will work with regular abstract classes (given proper polymorphic module), but I can edit commit message myself.

Thanks for your contribution!

@sandwwraith sandwwraith merged commit cfce5d8 into Kotlin:master Apr 25, 2023
3 checks passed
@sandwwraith
Copy link
Member

Next time, please open the PR against dev branch.

@EdwarDDay EdwarDDay deleted the properties_format_support_wrapped_polymorphics branch April 25, 2023 15:31
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.

None yet

3 participants