I'm using the kotlin driver and MongoDB is not allowing me to make my data class serializable so far.
Here's the class, before I add what I've tried:
@Serializable
data class Word(
@SerialName("_id")
@Contextual
val id: ObjectId,
val pos: String,
val word: String,
val hyphenation: String? = null,
val related: List<String>? = null,
val derived: List<String>? = null,
val senses: List<Sense>,
val forms: VerbConjugation?,
val searchSet: Set<String>
)
Without the @Serializable annotation added, MongoDB does not give any errors.
When added @Serializable with @Contextual as the official website suggests, it crashes with:
kotlinx.serialization.SerializationException: Serializer for class 'ObjectId' is not found. Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.
Making the id nullable does not change anything. I've been stuck here for hours. Please help!