-
Notifications
You must be signed in to change notification settings - Fork 667
Mention type unsoundness of serializer() in the documentation
#2998
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -58,14 +58,14 @@ public inline fun <reified T> SerializersModule.serializer(): KSerializer<T> { | |||||
| * Creates a serializer for the given [type]. | ||||||
| * [type] argument is usually obtained with [typeOf] method. | ||||||
| * | ||||||
| * This overload works with full type information, including type arguments and nullability, | ||||||
| * and is a recommended way to retrieve a serializer. | ||||||
| * For example, `serializer<typeOf<List<String?>>>()` returns [KSerializer] that is able | ||||||
| * to serialize and deserialize list of nullable strings — i.e. `ListSerializer(String.serializer().nullable)`. | ||||||
| * | ||||||
| * Variance of [type]'s type arguments is not used by the serialization and is not taken into account. | ||||||
| * Star projections in [type]'s arguments are prohibited. | ||||||
| * | ||||||
| * **Pitfall**: the returned serializer may return incorrect results or throw a [ClassCastException] if it receives | ||||||
| * a value that's not a valid instance of the [KType], even though the type allows passing such a value. | ||||||
| * Consider using the `serializer()` overload accepting a type argument (for example, `serializer<List<String>>()`), | ||||||
| * which returns the serializer with the correct type. | ||||||
| * | ||||||
| * @throws SerializationException if serializer cannot be created (provided [type] or its type argument is not serializable). | ||||||
| * @throws IllegalArgumentException if any of [type]'s arguments contains star projection | ||||||
| */ | ||||||
|
|
@@ -80,11 +80,16 @@ public fun serializer(type: KType): KSerializer<Any?> = EmptySerializersModule() | |||||
| * The nullability of returned serializer is specified using the [isNullable]. | ||||||
| * | ||||||
| * Note that it is impossible to create an array serializer with this method, | ||||||
| * as array serializer needs additional information: type token for an element type. | ||||||
| * as an array serializer needs additional information: type token for an element type. | ||||||
| * To create array serializer, use overload with [KType] or [ArraySerializer] directly. | ||||||
| * | ||||||
| * Caching on JVM platform is disabled for this function, so it may work slower than an overload with [KType]. | ||||||
| * | ||||||
| * **Pitfall**: the returned serializer may return incorrect results or throw a [ClassCastException] if it receives | ||||||
| * a value that's not a valid instance of the [KType], even though the type allows passing such a value. | ||||||
|
||||||
| * a value that's not a valid instance of the [KType], even though the type allows passing such a value. | |
| * a value that's not a valid instance of the [KClass], even though the type allows passing such a value. |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what this dependent-type-style syntax means and was assuming that this was a copy-paste artifact of some sort.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I mistyped the function call: it should be
serializer(typeOf<List<String?>>()). Can you please bring this paragraph back in the correct form?