Provide Jackson built-in Serializer & Deserializer classes for Mongo Geometry classes
See original GitHub issueI am getting com.fasterxml.jackson.databind.JsonMappingException: Cannot deserialize Class MainKt$main$PointTest (of type local/anonymous) as a Bean when using a Mongo Point class with the Jackson client.
Here is some code to reproduce the error
import com.fasterxml.jackson.databind.JsonMappingException
import com.mongodb.client.model.geojson.Point
import com.mongodb.client.model.geojson.Position
import org.litote.kmongo.KMongo
import org.litote.kmongo.getCollection
fun main() {
data class PointTest(val location: Point)
val client = KMongo.createClient() //get com.mongodb.MongoClient new instance
val database = client.getDatabase("test") //normal java driver usage
val col = database.getCollection<PointTest>() //KMongo extension method
col.insertOne(PointTest(Point(Position(20.0, 20.0))))
try {
col.find().toList()
} catch (e: JsonMappingException) {
e.printStackTrace()
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Provide Jackson built-in Serializer & Deserializer classes for Mongo ...
I am getting com.fasterxml.jackson.databind.JsonMappingException: Cannot deserialize Class MainKt$main$PointTest (of type local/anonymous) as a Bean when ...
Read more >Definitive Guide to Jackson ObjectMapper - Serialize and ...
The ObjectMapper class allows you to register a custom serializer or deserializer for these cases. This feature is helpful when the JSON ...
Read more >Spring Data MongoDB - Reference Documentation
A Using the DomainClassConverter Class to let Spring MVC resolve instances of repository-managed domain classes from request parameters or path variables.
Read more >Polymorphic (de-)serialization to specific type if field type is an ...
The geometry field could be GeoJsonPolygon or GeoJsonPoint . I also added this MixIn class: @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, include = ...
Read more >Serialization Tutorial - GitHub Pages
The main way the default serializer handles serialization is through “class maps”. A class map is a structure that defines the mapping between...
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

@octawizard Remove the kmongo dependency (jackson mapping) - just keep the kmongo-native dependency
thank you @zigzago !