Closed K1rakishou closed 3 days ago
Hi, this comes from the limitation from kotlinx-serialization where it drops information about generic types, e.g.:
class TestType(
val first: SomeType<String>,
val second: SomeType<Int>,
)
I need to handle SomeType<String>
and SomeType<Int>
as two different types that generate different schemas, but kotlinx "only" keeps the information that it is SomeType
.
The workaround I decided on was to duplicate types that were already encountered, resulting in SomeType
and SomeType#12345
. Without that, information about the generic type could be mixed up and e.g. both SomeType
s would be incorrectly treated as SomeType<String>
or SomeType<Int>
.
Unfortunatly, this behavior can also affect types/setups, where this would not be needed (like in your case).
I'm not sure if there is another reliable solution, approach or way to detect that two types have different/same/no type parameters :thinking:
A workaround to manually fix your problem would be to tell the processing step that the type does not have generic type parameters and that this behavior is not neccesary.
//...
.processKotlinxSerialization {
markNotParameterized<Something>()
}
//...
I see. Indeed, using markNotParameterized<Something>()
solves the issue. Thank you!
Hi. After trying to update to the latest version, I have noticed this behavior.
They are both the same type, but one is nullable, the other one is non-nullable.
The problem seems to be in KotlinxSerializationTypeProcessingStep.kt
When checking if the type is already defined
the nullability information is removed from full type name. Here we can see that the type is nullable:
But then when creating a type for searching
descriptor.cleanSerialName()
is used:where
cleanSerialName()
is removing the?
:Because of that
typeData.find(descriptor, typeParameters) != null
returns non-null value andgetUniqueId
returns TypeId with random value added to it (withAdditionalId
is true).If I remove nullability from
second
parameter then everything works as expected. Also if I reorderfirst
andsecond
fields inTestType
thenfirst
field will have random numbers added to it instead ofsecond
which is nullable. So the problem is not in using nullability but in checking if a type was already defined to deduplicate them.I have tried to use a
typeRedirect
fromSomething?
->Something
but unfortunately it didn't help.