Skip to content

Commit a46299e

Browse files
authored
Expand @SerialInfo doc with information on targets (#1926)
1 parent 85986d8 commit a46299e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

core/commonMain/src/kotlinx/serialization/Annotations.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,12 @@ public annotation class EncodeDefault(val mode: Mode = Mode.ALWAYS) {
181181
/**
182182
* Meta-annotation that commands the compiler plugin to handle the annotation as serialization-specific.
183183
* Serialization-specific annotations are preserved in the [SerialDescriptor] and can be retrieved
184-
* during serialization process with [SerialDescriptor.getElementAnnotations].
184+
* during serialization process with [SerialDescriptor.getElementAnnotations] for properties annotations
185+
* and [SerialDescriptor.annotations] for class annotations.
186+
*
187+
* It is recommended to explicitly specify target for serial info annotations, whether it is [AnnotationTarget.PROPERTY], [AnnotationTarget.CLASS], or both.
188+
* Keep in mind that Kotlin compiler prioritizes [function parameter target][AnnotationTarget.VALUE_PARAMETER] over [property target][AnnotationTarget.PROPERTY],
189+
* so serial info annotations used on constructor-parameters-as-properties without explicit declaration-site or use-site target are not preserved.
185190
*/
186191
@Target(AnnotationTarget.ANNOTATION_CLASS)
187192
@Retention(AnnotationRetention.BINARY)

0 commit comments

Comments
 (0)