Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance KotlinSerializer with value codecs for widening primitive conversion. #1301

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

vbabanin
Copy link
Member

@vbabanin vbabanin requested review from a team and rozza and removed request for a team January 31, 2024 01:29
@vbabanin vbabanin self-assigned this Jan 31, 2024
@rozza
Copy link
Member

rozza commented Jan 31, 2024

Kotlinx Json has a configuration to allow for lenient parsing: https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/json.md#lenient-parsing

Should this be configurable?

@jyemin
Copy link
Contributor

jyemin commented Jun 17, 2024

@rozza I think in this case it's better to be consistent with other codecs and also with the way numeric values are treated in MongoDB is basically interchangeable and compatible with each other, so long as there is no loss of precision or magnitude.

@jyemin
Copy link
Contributor

jyemin commented Jun 17, 2024

@vbabanin can this come out of Draft now?

JAVA-5303
@vbabanin vbabanin marked this pull request as ready for review July 1, 2024 22:42
<!-- MongoDB status: "False Positive", SpotBugs rank: 17 -->
<Class name="org.bson.codecs.kotlinx.KotlinSerializerCodec$Companion"/>
<Method name="~.*validateAnnotations.*"/>
<Bug pattern="BC_BAD_CAST_TO_ABSTRACT_COLLECTION"/>
Copy link
Member Author

@vbabanin vbabanin Jul 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning is triggered by an implicit cast generated during Kotlin to Java bytecode compilation, which is not directly controllable in the source Kotlin code. As this casting is safely handled by the Kotlin compiler and does not reflect an actual error in our Kotlin source, we can suppress this warning.

@@ -34,8 +34,18 @@ import org.bson.BsonReader
import org.bson.BsonReaderMark
import org.bson.BsonType
import org.bson.BsonValue
import org.bson.codecs.BooleanCodec
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we discussed not using codecs (so to not confuse the two concepts of codecs and kserializers. Instead use the NumberCodecHelper directly (which is what the numeric codecs are doing in decode anyway).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants