Do not add any .childSerializers() stuff if user explicitly marked custom serializer as KSerializer
todo: better design for user-provided descriptors and and schema hierarchy
This commit is contained in:
+3
@@ -72,6 +72,9 @@ abstract class SerializerCodegen(
|
||||
|
||||
val localSerializersFieldsDescriptors: List<PropertyDescriptor> = findLocalSerializersFieldDescriptors()
|
||||
|
||||
// Can be false if user specified inheritance from KSerializer explicitly
|
||||
protected val isGeneratedSerializer = serializerDescriptor.typeConstructor.supertypes.any(::isGeneratedKSerializer)
|
||||
|
||||
private fun findLocalSerializersFieldDescriptors(): List<PropertyDescriptor> {
|
||||
val count = serializableDescriptor.declaredTypeParameters.size
|
||||
if (count == 0) return emptyList()
|
||||
|
||||
+6
-5
@@ -81,11 +81,12 @@ class SerializerIrGenerator(val irClass: IrClass, override val compilerContext:
|
||||
compilerContext.localSymbolTable.withScope(initIrBody.descriptor) {
|
||||
initIrBody.body = compilerContext.createIrBuilder(initIrBody.symbol).irBlockBody {
|
||||
val localDesc = irTemporary(
|
||||
irInvoke(null, serialClassDescImplCtor,
|
||||
irString(serialName), irGet(thisAsReceiverParameter),
|
||||
typeHint = serialClassDescImplCtor.owner.returnType
|
||||
),
|
||||
nameHint = "serialDesc"
|
||||
irInvoke(
|
||||
null, serialClassDescImplCtor,
|
||||
irString(serialName), if (isGeneratedSerializer) irGet(thisAsReceiverParameter) else irNull(),
|
||||
typeHint = serialClassDescImplCtor.owner.returnType
|
||||
),
|
||||
nameHint = "serialDesc"
|
||||
)
|
||||
|
||||
fun addFieldCall(fieldName: String) =
|
||||
|
||||
+4
-1
@@ -58,7 +58,10 @@ class SerializerJsTranslator(descriptor: ClassDescriptor,
|
||||
|
||||
// this.serialDesc = new SerialDescImpl(...)
|
||||
val correctThis = context.getDispatchReceiver(JsDescriptorUtils.getReceiverParameterForDeclaration(desc.containingDeclaration))
|
||||
val value = JsNew(context.getInnerReference(serialDescImplConstructor), listOf(JsStringLiteral(serialName), correctThis))
|
||||
val value = JsNew(
|
||||
context.getInnerReference(serialDescImplConstructor),
|
||||
listOf(JsStringLiteral(serialName), if (isGeneratedSerializer) correctThis else JsNullLiteral())
|
||||
)
|
||||
val assgmnt = TranslationUtils.assignmentToBackingField(context, desc, value)
|
||||
translator.addInitializerStatement(assgmnt.makeStmt())
|
||||
|
||||
|
||||
+4
-1
@@ -80,7 +80,10 @@ class SerializerCodegenImpl(
|
||||
if (isStatic) {
|
||||
assert(serializerDescriptor.kind == ClassKind.OBJECT) { "Serializer for type without type parameters must be an object" }
|
||||
// static descriptor means serializer is an object. it is safer to get it from correct field
|
||||
StackValue.singleton(serializerDescriptor, codegen.typeMapper).put(generatedSerializerType, this)
|
||||
if (isGeneratedSerializer)
|
||||
StackValue.singleton(serializerDescriptor, codegen.typeMapper).put(generatedSerializerType, this)
|
||||
else
|
||||
aconst(null)
|
||||
} else {
|
||||
load(0, serializerAsmType)
|
||||
}
|
||||
|
||||
+1
@@ -176,6 +176,7 @@ object KSerializerDescriptorResolver {
|
||||
val isLoad = name == SerialEntityNames.LOAD_NAME &&
|
||||
shouldAddSerializerFunction { classDescriptor.checkLoadMethodParameters(it.valueParameters) }
|
||||
val isDescriptorGetter = name == SerialEntityNames.GENERATED_DESCRIPTOR_GETTER &&
|
||||
thisDescriptor.typeConstructor.supertypes.any(::isGeneratedKSerializer) &&
|
||||
shouldAddSerializerFunction { true /* TODO? */ }
|
||||
|
||||
if (isSave || isLoad || isDescriptorGetter) {
|
||||
|
||||
Reference in New Issue
Block a user