Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SerializationException when querying a column that isn't a primitive #12

Closed
JvmName opened this issue Jan 29, 2025 · 4 comments · Fixed by #15
Closed

SerializationException when querying a column that isn't a primitive #12

JvmName opened this issue Jan 29, 2025 · 4 comments · Fixed by #15

Comments

@JvmName
Copy link
Member

JvmName commented Jan 29, 2025

Failing test:

@Test
fun select_inList()  = runTest{
    val expectedO = TestObject()
    testObjectStorage.insert(expectedO.id, expectedO)

    val expectedList = expectedO.list.map { it.createdAt.toString() }

    val actual = testObjectStorage.select(
        where = TestObject::list.then(TestObjectChild::createdAt) inList expectedList
    ).first() // 💥 SerializationException!

    assertEquals(expectedO, actual.first())
    assertEquals(expectedO.list, actual.first().list)
}

Stacktrace:

Serializer for class 'kotlin.Any' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.

kotlinx.serialization.SerializationException: Serializer for class 'kotlin.Any' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.

	at kotlinx.serialization.SerializersKt__SerializersKt.noCompiledSerializer(Serializers.kt:380)
	at kotlinx.serialization.SerializersKt.noCompiledSerializer(Unknown Source)
	at com.mercury.sqkon.db.KeyValueStorageTest$select_inList$1.invokeSuspend(KeyValueStorageTest.kt:587)
	at com.mercury.sqkon.db.KeyValueStorageTest$select_inList$1.invoke(KeyValueStorageTest.kt)
	at com.mercury.sqkon.db.KeyValueStorageTest$select_inList$1.invoke(KeyValueStorageTest.kt)
	at kotlinx.coroutines.test.TestBuildersKt__TestBuildersKt$runTest$2$1$1.invokeSuspend(TestBuilders.kt:317)

If you follow the inlined part of the stacktrace, the failure is right on this line:

valueDescriptor = serializer<V>().descriptor

@JvmName JvmName changed the title SerializationException when column isn't a primitive &#x60;SerializationException&#x60; when querying a column that isn&#x27;t a primitive Jan 29, 2025
@JvmName JvmName changed the title &#x60;SerializationException&#x60; when querying a column that isn&#x27;t a primitive SerializationException when querying a column that isn't a primitive Jan 29, 2025
@JvmName
Copy link
Member Author

JvmName commented Jan 31, 2025

Update, one level deeper:

  • the JsonPathBuilder factory methods invoke serializer<V>() in order to get the KSerializer to get SerialDescriptor info
  • KeyValueStorage uses KotlinSqkonSerializer, which is actually configurable for how an object gets serialized
  • I suspect, ideally, JsonPathBuilder would like to use KVS's KotlinSqkonSerializer, but I don't see an obvious way to plumb it into QueryExt and JsonPathNode...

@chrisjenx
Copy link
Collaborator

This this is because the sub type is a Collection so we don't get the type of the Collection so it's effectively doing:

serializer<Collection<V>>

It's tricky to fix this, ideally we need to know if the Type is collection so we get the generic, but we can't do that without reflection easily 😢

@chrisjenx
Copy link
Collaborator

Oh so the fix is:

where = TestObject::class.withList(TestObject::list) {
                then(TestObjectChild::createdAt)
            } inList expectedList

@chrisjenx
Copy link
Collaborator

Should get easier to use the api with lists with #15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants