Closed Xfel closed 2 years ago
As a workaround I suggest you use a custom serializer
HTH
That does not help.
Using a serializer:
class StopTypeSerializer : JsonSerializer<StopType>() {
override fun serialize(value: StopType, gen: JsonGenerator, serializers: SerializerProvider?) {
gen.writeNumber(value.value)
}
}
I get:
Exception in thread "main" java.lang.IllegalArgumentException: state should be: length >= 5
at org.bson.assertions.Assertions.isTrueArgument(Assertions.java:62)
at org.bson.RawBsonDocument.<init>(RawBsonDocument.java:110)
at org.bson.RawBsonDocument.<init>(RawBsonDocument.java:92)
at org.litote.kmongo.jackson.JacksonCodec.encode(JacksonCodec.kt:188)
When adding a specific format visitor to the serializer:
override fun acceptJsonFormatVisitor(visitor: JsonFormatVisitorWrapper, type: JavaType?) {
visitor.expectIntegerFormat(type)
}
I instead get:
Exception in thread "main" org.bson.BsonInvalidOperationException: readInt64 can only be called when CurrentBSONType is INT64, not when CurrentBSONType is INT32.
at org.bson.AbstractBsonReader.verifyBSONType(AbstractBsonReader.java:689)
at org.bson.AbstractBsonReader.checkPreconditions(AbstractBsonReader.java:721)
at org.bson.AbstractBsonReader.readInt64(AbstractBsonReader.java:372)
at org.litote.kmongo.jackson.JacksonCodec.encode(JacksonCodec.kt:195)
Even if I add a toLong() in the serializer, the error stays the same.
Second workaround (without serializer) - tested ;)
col.find(Stop::type from StopType.STATION.value).toList()
Type checking is bypassed
fixed in next release
where StopType is annotated to use int values:
gives exception: