0

I'm trying out kmongo in my new spring boot application. With kmongo I'm using kotlin serialisation and getting an error when reading from db.

In DB, I've a Decimal128 field in my collection, I'm trying to deserialise it into a Double (or BigDecimal) field rate in Rate class.

@Serializable
data class Rate(
    val type: ConsultationType,
    val rate: Double,
    .... other fields
)

enum class ConsultationType {
    MESSAGE, VOICE, VIDEO
}

It is giving error:

org.bson.BsonInvalidOperationException: readDouble can only be called when CurrentBSONType is DOUBLE, not when CurrentBSONType is DECIMAL128.
    at org.bson.AbstractBsonReader.verifyBSONType(AbstractBsonReader.java:689) ~[bson-4.6.1.jar:na]
    at org.bson.AbstractBsonReader.checkPreconditions(AbstractBsonReader.java:721) ~[bson-4.6.1.jar:na]
    at org.bson.AbstractBsonReader.readDouble(AbstractBsonReader.java:316) ~[bson-4.6.1.jar:na]
    at com.github.jershell.kbson.FlexibleDecoder.decodeDouble(BsonFlexibleDecoder.kt:110) ~[kbson-0.4.5.jar:na]
    at kotlinx.serialization.encoding.AbstractDecoder.decodeDoubleElement(AbstractDecoder.kt:56) ~[kotlinx-serialization-core-jvm-1.4.1.jar:1.4.1]

In spring data mongo we could do:

@Field(targetType = DECIMAL128)
private BigDecimal value;

With kmongo and kotlin serialisation, What is the proper way to do this?

Drunken Daddy
  • 7,326
  • 14
  • 70
  • 104

0 Answers0