question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide Jackson built-in Serializer & Deserializer classes for Mongo Geometry classes

See original GitHub issue

I 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:open
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
zigzagocommented, Nov 3, 2020

@octawizard Remove the kmongo dependency (jackson mapping) - just keep the kmongo-native dependency

0reactions
octawizardcommented, Nov 4, 2020

thank you @zigzago !

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found