You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Attempts to create a serializer for the given [type] and fallbacks to [contextual][SerializersModule.getContextual]
53
-
* lookup for non-serializable types.
54
-
* [type] argument can be obtained with experimental [typeOf] method.
92
+
* Retrieves default serializer for the given [type] and,
93
+
* if [type] is not serializable, fallbacks to [contextual][SerializersModule.getContextual] lookup.
94
+
* [type] argument is usually obtained with [typeOf] method.
95
+
*
96
+
* This overload works with full type information, including type arguments and nullability,
97
+
* and is a recommended way to retrieve a serializer.
98
+
* For example, `serializer<typeOf<List<String?>>>()` returns [KSerializer] that is able
99
+
* to serialize and deserialize list of nullable strings — i.e. `ListSerializer(String.serializer().nullable)`.
100
+
*
101
+
* Variance of [type]'s arguments is not used by the serialization and is not taken into account.
102
+
* Star projections in [type]'s arguments are prohibited.
103
+
*
55
104
* @throws SerializationException if serializer cannot be created (provided [type] or its type argument is not serializable and is not registered in [this] module).
105
+
* @throws IllegalArgumentException if any of [type]'s arguments contains star projection
* Attempts to create a serializer for the given [type] and fallbacks to [contextual][SerializersModule.getContextual]
64
-
* lookup for non-serializable types.
65
-
* [type] argument can be obtained with experimental [typeOf] method.
66
-
* Returns `null` if serializer cannot be created (provided [type] or its type argument is not serializable and is not registered in [this] module).
112
+
* Retrieves default serializer for the given [type] and,
113
+
* if [type] is not serializable, fallbacks to [contextual][SerializersModule.getContextual] lookup.
114
+
* [type] argument is usually obtained with [typeOf] method.
115
+
*
116
+
* This overload works with full type information, including type arguments and nullability,
117
+
* and is a recommended way to retrieve a serializer.
118
+
* For example, `serializerOrNull<typeOf<List<String?>>>()` returns [KSerializer] that is able
119
+
* to serialize and deserialize list of nullable strings — i.e. `ListSerializer(String.serializer().nullable)`.
120
+
*
121
+
* Variance of [type]'s arguments is not used by the serialization and is not taken into account.
122
+
* Star projections in [type]'s arguments are prohibited.
123
+
*
124
+
* @returns [KSerializer] for the given [type] or `null` if serializer cannot be created (given [type] or its type argument is not serializable and is not registered in [this] module).
125
+
* @throws IllegalArgumentException if any of [type]'s arguments contains star projection
else->throwIllegalArgumentException("typeToken should be an instance of Class<?>, GenericArray, ParametrizedType or WildcardType, but actual type is $type${type::class}")
146
+
else->throwIllegalArgumentException("type should be an instance of Class<?>, GenericArrayType, ParametrizedType or WildcardType, but actual argument $typehas type ${type::class}")
128
147
}
129
148
130
149
@OptIn(ExperimentalSerializationApi::class)
@@ -177,5 +196,5 @@ private fun Type.prettyClass(): Class<*> = when (val it = this) {
else->throwIllegalArgumentException("typeToken should be an instance of Class<?>, GenericArray, ParametrizedType or WildcardType, but actual type is $it${it::class}")
199
+
else->throwIllegalArgumentException("type should be an instance of Class<?>, GenericArrayType, ParametrizedType or WildcardType, but actual argument $it has type${it::class}")
0 commit comments