Parcelize: Serialize primitive arrays correctly when the custom parceler is provided.

This fixes failing 'customSerializerBoxing' test.
This commit is contained in:
Yan Zhulanow
2018-04-16 23:59:25 +03:00
parent defe97e4ef
commit ee37bcf14b
@@ -83,27 +83,37 @@ interface ParcelSerializer {
val className = asmType.className
fun strict() = strict && !type.annotations.hasAnnotation(RAWVALUE_ANNOTATION_FQNAME)
type.annotations.findAnnotation(WRITE_WITH_FQNAME)?.let { writeWith ->
val parceler = writeWith.type.arguments.singleOrNull()?.type
if (parceler != null && !parceler.isError) {
return TypeParcelerParcelSerializer(asmType, parceler, context.typeMapper)
fun findCustomParcelerType(type: KotlinType): KotlinType? {
type.annotations.findAnnotation(WRITE_WITH_FQNAME)?.let { writeWith ->
val parceler = writeWith.type.arguments.singleOrNull()?.type
if (parceler != null && !parceler.isError) {
return parceler
}
}
return context.findParcelerClass(type)?.takeIf { !it.isError }
}
context.findParcelerClass(type)?.let { typeParceler ->
if (!typeParceler.isError) {
return TypeParcelerParcelSerializer(asmType, typeParceler, context.typeMapper)
}
}
findCustomParcelerType(type)?.let { return TypeParcelerParcelSerializer(asmType, it, context.typeMapper) }
return when {
asmType.descriptor == "[I"
|| asmType.descriptor == "[Z"
|| asmType.descriptor == "[B"
|| asmType.descriptor == "[C"
|| asmType.descriptor == "[D"
|| asmType.descriptor == "[F"
|| asmType.descriptor == "[L" -> PrimitiveArrayParcelSerializer(asmType)
|| asmType.descriptor == "[Z"
|| asmType.descriptor == "[B"
|| asmType.descriptor == "[C"
|| asmType.descriptor == "[S"
|| asmType.descriptor == "[D"
|| asmType.descriptor == "[F"
|| asmType.descriptor == "[J" -> {
val customElementParcelerType = findCustomParcelerType(type.builtIns.getArrayElementType(type))
if (customElementParcelerType != null) {
val elementType = asmType.elementType
val elementParceler = TypeParcelerParcelSerializer(elementType, customElementParcelerType, context.typeMapper)
ArrayParcelSerializer(asmType, elementParceler)
} else {
PrimitiveArrayParcelSerializer(asmType)
}
}
asmType.descriptor == "[Landroid/os/IBinder;" -> NullCompliantObjectParcelSerializer(asmType,
Method("writeBinderArray"), Method("createBinderArray"))