kotlin data class can not be decoded
See original GitHub issuedata class ShipDetail(
var _id: String? = null,
var order_id: String? = null)
val collection = database.getCollection<ShipDetail>("ship_detail")
var r = collection.findOne();
produce exception:
Exception in thread “main” org.bson.codecs.configuration.CodecConfigurationException: Can’t find a codec for class ShipDetail. at org.bson.codecs.configuration.CodecCache.getOrThrow(CodecCache.java:46) at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:63) at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:37) at com.mongodb.FindIterableImpl.createQueryOperation(FindIterableImpl.java:228) at com.mongodb.FindIterableImpl.execute(FindIterableImpl.java:224) at com.mongodb.FindIterableImpl.first(FindIterableImpl.java:205) at org.litote.kmongo.ExtensionsKt.findOne(extensions.kt:163) at org.litote.kmongo.ExtensionsKt.findOne$default(extensions.kt:162)
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Data classes
In Kotlin, these are called data classes and are marked with data : ... Data classes cannot be abstract, open, sealed, or inner....
Read more >Kotlin data class copy method not deep copying all members
It seems like for some members, a (deep) copy is not actually created and the references are still to the original.
Read more >MongoDB CodecConfigurationException for Kotlin data class
I am new to kotlin and mongo db. Cannot find a public constructor for 'TodoItem'. A custom Codec or PojoCodec may need to...
Read more >Introduction to Data Classes in Kotlin
Although the properties of a data class can be mutable (declared using var ), It's strongly recommended to use immutable properties (declared ...
Read more >Kotlin Data Class
In this article, you will learn to create data classes in Kotlin. You will also learn about requirements that data class must fulfill,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@frzleaf Replace the line val client = MongoClient(MongoClientURI(“mongodb://root:secret$@localhost:27017/ship_info”)) with val client = KMongo.createClient(MongoClientURI(“mongodb://root:secret$@localhost:27017/ship_info”)) and it should work
Thank you so much, it worked 😄
MongoClient object must be created by KMongo with codecRegistry = DEFAULT_CODEC_REGISTRY