Skip to content

Kotlin JSON: u128/i128 fields fail with "Serializer has not been found for type 'BigInteger'" #128

Description

@StuartHarris

Found in #126. With JsonPlugin, any module containing a u128 or i128 field fails to compile:

e: Serializer has not been found for type 'BigInteger'. To use context serializer as fallback, explicitly annotate type or property with @Contextual

Cause. The JSON plugin binds its BigIntegerSerializer through a same-file alias emitted from module_helpers (json/kotlin.rs, FEATURE_BIGINT):

typealias BigInteger = @Serializable(with = BigIntegerSerializer::class) BigInteger

but write_module_header (kotlin/emitter/mod.rs, around the Feature::BigInt check) unconditionally writes import java.math.BigInteger for the same modules. In Kotlin an explicit import outranks a same-package declaration, so every BigInteger in the file resolves to java.math.BigInteger and the alias, with its serializer annotation, is never used. The alias is also self-referential: its right-hand side is the bare BigInteger, which only means anything because of that import.

Verified fix shape. Qualifying the alias's right-hand side (... java.math.BigInteger, as the UUID alias already does) and dropping the emitter's import when the JSON plugin is active makes the whole main fixture compile. Qualifying the right-hand side alone is not enough because the import still wins. The clean version needs the emitter to know that a plugin is supplying the alias, or the import to move into the bincode plugin's imports() where it is actually needed.

The Kotlin compile test currently strips 128-bit fields from the main fixture (remove_128_bit_fields in tests/kotlin_generation.rs); that workaround should go once this is fixed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions