Skip to content

Commit 3e54de5

Browse files
authored
Actualize 'serializer not found' platform-specific message (#2339)
Fixes #1248
1 parent 7d597c1 commit 3e54de5

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

core/jsMain/src/kotlinx/serialization/internal/Platform.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ internal actual fun <T : Any, E : T?> ArrayList<E>.toNativeArrayImpl(eClass: KCl
4040

4141
internal actual fun KClass<*>.platformSpecificSerializerNotRegistered(): Nothing {
4242
throw SerializationException(
43-
"${notRegisteredMessage()}\n" +
44-
"On Kotlin/JS explicitly declared serializer should be used for interfaces and enums without @Serializable annotation"
43+
notRegisteredMessage() +
44+
"To get enum serializer on Kotlin/JS, it should be annotated with @Serializable annotation."
4545
)
4646
}
4747

core/nativeMain/src/kotlinx/serialization/internal/Platform.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ internal actual inline fun BooleanArray.getChecked(index: Int): Boolean {
1919

2020
internal actual fun KClass<*>.platformSpecificSerializerNotRegistered(): Nothing {
2121
throw SerializationException(
22-
"${notRegisteredMessage()}\n" +
23-
"On Kotlin/Native explicitly declared serializer should be used for interfaces and enums without @Serializable annotation"
22+
notRegisteredMessage() +
23+
"To get enum serializer on Kotlin/Native, it should be annotated with @Serializable annotation.\n" +
24+
"To get interface serializer on Kotlin/Native, use PolymorphicSerializer() constructor function.\n"
2425
)
2526
}
2627

docs/builtin-classes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ In JSON an enum gets encoded as a string.
166166
{"name":"kotlinx.serialization","status":"SUPPORTED"}
167167
```
168168

169+
> Note: On Kotlin/JS and Kotlin/Native, `@Serializable` annotation is needed for enum class if you want to use it as a root object — i.e. use `encodeToString<Status>(Status.SUPPORTED)`.
170+
169171
<!--- TEST -->
170172

171173
### Serial names of enum entries

docs/polymorphism.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ fun main() {
408408
{"type":"owned","name":"kotlinx.coroutines","owner":"kotlin"}
409409
```
410410

411+
> Note: On Kotlin/Native, you should use `format.encodeToString(PolymorphicSerializer(Project::class), data))` instead due to limited reflection capabilities.
412+
411413
<!--- TEST LINES_START -->
412414

413415
### Property of an interface type

0 commit comments

Comments
 (0)