Describe the bug
Deserializing generic types with spring cloud gcp spanner does not work.
If I have classes like this:
@Table(name = "MyEntity")
class MyEntity (
val id: String,
@Column(name = "jsonField", spannerType = TypeCode.JSON)
val myGenericJsonField: GenericType<SimpleType>,
)
data class GenericType<T> (
val genericField: T
)
data class SimpleType(
val test: String
)
with the following schema:
CREATE TABLE IF NOT EXISTS MyEntity(
id STRING(36) PRIMARY KEY,
jsonField JSON
)
After writing to spanner and reading the entity back it will not restore the generic type correctly. So instead of genericField being SimpleType, it fills it with a com.google.gson.internal.LinkedTreeMap.
The problem seems to be that in SpannerPersistenPropertyImpl.getColumnInnerType not the whole TypeInformation is preserved, so later there is no way to give gson a TypeToken to actually reconstruct the correct type.
Sample
There is a reproduction repo here: https://github.com/hesch/spring-cloud-gcp-generic-repro
With a test that fails here: https://github.com/hesch/spring-cloud-gcp-generic-repro/blob/main/src/test/kotlin/org/example/GenericTest.kt
Describe the bug
Deserializing generic types with spring cloud gcp spanner does not work.
If I have classes like this:
with the following schema:
After writing to spanner and reading the entity back it will not restore the generic type correctly. So instead of
genericFieldbeingSimpleType, it fills it with acom.google.gson.internal.LinkedTreeMap.The problem seems to be that in
SpannerPersistenPropertyImpl.getColumnInnerTypenot the wholeTypeInformationis preserved, so later there is no way to give gson aTypeTokento actually reconstruct the correct type.Sample
There is a reproduction repo here: https://github.com/hesch/spring-cloud-gcp-generic-repro
With a test that fails here: https://github.com/hesch/spring-cloud-gcp-generic-repro/blob/main/src/test/kotlin/org/example/GenericTest.kt