From bd1460590ce0aaff529f096c96791b9ee1725e3f Mon Sep 17 00:00:00 2001 From: Julien Buret Date: Wed, 6 Jul 2022 20:43:51 +0200 Subject: [PATCH] test #354 --- .../kotlin/Issue354KotlinIdFieldIgnored.kt | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 kmongo-serialization/src/test/kotlin/Issue354KotlinIdFieldIgnored.kt diff --git a/kmongo-serialization/src/test/kotlin/Issue354KotlinIdFieldIgnored.kt b/kmongo-serialization/src/test/kotlin/Issue354KotlinIdFieldIgnored.kt new file mode 100644 index 00000000..aae2d99c --- /dev/null +++ b/kmongo-serialization/src/test/kotlin/Issue354KotlinIdFieldIgnored.kt @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2016/2021 Litote + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.litote.kmongo.issues + +import kotlinx.serialization.Contextual +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import org.bson.Document +import org.bson.types.ObjectId +import org.junit.Test +import org.litote.kmongo.AllCategoriesKMongoBaseTest +import org.litote.kmongo.findOne +import org.litote.kmongo.withDocumentClass +import kotlin.test.assertEquals +import kotlin.test.assertNull + +@Serializable +data class TestData(@SerialName("_id") @Contextual val id: ObjectId = ObjectId(), val value: String) + +/** + * + */ +class Issue354KotlinIdFieldIgnored : AllCategoriesKMongoBaseTest() { + + @Test + fun testSerialization() { + val test = TestData(value = "Foo") + + col.insertOne(test) + val test2 = col.findOne() + + assertEquals(test, test2) + + val doc = col.withDocumentClass().findOne() + assertEquals(test.id, doc?.get("_id")) + assertNull(doc?.get("id")) + } +} \ No newline at end of file