Skip to content

Commit

Permalink
Do not report 'Missing @serializable on enum with @SerialInfo' if enum
Browse files Browse the repository at this point in the history
has custom serializer

#KT-34991 Fixed

(cherry picked from commit 73b9d24)
  • Loading branch information
sandwwraith committed Nov 25, 2019
1 parent 6b773bc commit 0d97db0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ open class SerializationPluginDeclarationChecker : DeclarationChecker {

private fun ClassDescriptor.isSerializableEnumWithMissingSerializer(): Boolean {
if (kind != ClassKind.ENUM_CLASS) return false
if (hasSerializableAnnotationWithoutArgs) return false
if (annotations.hasAnnotation(SerializationAnnotations.serializableAnnotationFqName)) return false
if (annotations.hasAnySerialAnnotation) return true
return enumEntries().any { (it.annotations.hasAnySerialAnnotation) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@ enum class SimpleEnum { A, B }
<!PLUGIN_WARNING("Explicit @Serializable annotation on enum class is required when @SerialName or @SerialInfo annotations are used on its members.")!>enum<!> class MarkedInfoEnum { @SerialId(10) A, B}

@Serializable
enum class ExplicitlyMarkedEnum { @SerialId(10) A, B}
enum class ExplicitlyMarkedEnum { @SerialId(10) A, B}

@Serializable(EnumSerializer::class)
enum class ExplicitlyMarkedEnumCustom { @SerialId(10) A, B}

object EnumSerializer: KSerializer<ExplicitlyMarkedEnumCustom> {
override val descriptor = TODO()
override fun serialize(encoder: Encoder, obj: ExplicitlyMarkedEnumCustom) = TODO()
override fun deserialize(decoder: Decoder): ExplicitlyMarkedEnumCustom = TODO()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package

public object EnumSerializer : kotlinx.serialization.KSerializer<ExplicitlyMarkedEnumCustom> {
private constructor EnumSerializer()
public open override /*1*/ val descriptor: kotlin.Nothing
public open override /*1*/ fun deserialize(/*0*/ decoder: kotlinx.serialization.Decoder): ExplicitlyMarkedEnumCustom
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun patch(/*0*/ decoder: kotlinx.serialization.Decoder, /*1*/ old: ExplicitlyMarkedEnumCustom): ExplicitlyMarkedEnumCustom
public open override /*1*/ fun serialize(/*0*/ encoder: kotlinx.serialization.Encoder, /*1*/ obj: ExplicitlyMarkedEnumCustom): kotlin.Nothing
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}

@kotlinx.serialization.Serializable public final enum class ExplicitlyMarkedEnum : kotlin.Enum<ExplicitlyMarkedEnum> {
@kotlinx.serialization.SerialId(id = 10) enum entry A

Expand Down Expand Up @@ -41,6 +52,27 @@ package
public final /*synthesized*/ fun values(): kotlin.Array<ExplicitlyMarkedEnum>
}

@kotlinx.serialization.Serializable(with = EnumSerializer::class) public final enum class ExplicitlyMarkedEnumCustom : kotlin.Enum<ExplicitlyMarkedEnumCustom> {
@kotlinx.serialization.SerialId(id = 10) enum entry A

enum entry B

private constructor ExplicitlyMarkedEnumCustom()
public final override /*1*/ /*fake_override*/ val name: kotlin.String
public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int
protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any
public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: ExplicitlyMarkedEnumCustom): kotlin.Int
public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
protected/*protected and package*/ final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit
public final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class<ExplicitlyMarkedEnumCustom!>!
public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String

// Static members
public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): ExplicitlyMarkedEnumCustom
public final /*synthesized*/ fun values(): kotlin.Array<ExplicitlyMarkedEnumCustom>
}

public final enum class MarkedInfoEnum : kotlin.Enum<MarkedInfoEnum> {
@kotlinx.serialization.SerialId(id = 10) enum entry A

Expand Down

0 comments on commit 0d97db0

Please sign in to comment.