Repository navigation
Support polymorphic type info for unsigned integer types - #459
Merged
Merged
Conversation
The UByte/UShort/UInt/ULong serializers extended StdSerializer directly and did not implement `serializeWithType()`, so an unsigned number failed to serialize whenever type information was required for it: an `Any` property under default typing, a property annotated with `@JsonTypeInfo` (including collection contents), or a nullable unsigned property under `DefaultTyping.EVERYTHING`. Schema generators were also told the type is "any". Make the serializers extend StdScalarSerializer, whose `serializeWithType()` writes the type id followed by the numeric value, and implement `acceptJsonFormatVisitor()` with the integer format. The deserializers already read the typed form and are left unchanged. Ported from FasterXML/jackson-module-kotlin#1228. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0137oSJi6gZrpgW99q17VZVL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Port of FasterXML/jackson-module-kotlin#1228.
Problem
UByteSerializer/UShortSerializer/UIntSerializer/ULongSerializerextendedStdSerializerdirectly and did not implementserializeWithType(). As a result, serializing an unsigned number failed with "Type id handling not implemented" whenever type information was required:Anyproperty under default typing@JsonTypeInfo(including collection contents)DefaultTyping.EVERYTHINGFor the same reason, schema generators were told the type is "any".
Changes
StdScalarSerializer, whoseserializeWithType()writes the type id followed by the numeric value (e.g.["kotlin.UInt",1]).acceptJsonFormatVisitor()reports the integer format (INT/INT/LONG/BIG_INTEGER), sinceStdScalarSerializerassumes a string by default.Tests
Ported
UnsignedNumbersTypeInfoTestandUnsignedNumbersJsonFormatVisitorTestintozPorted/test. Without the fix, 30 of the 55 unsigned-number tests fail; with it,./gradlew lintKotlin testpasses.🤖 Generated with Claude Code
https://claude.ai/code/session_0137oSJi6gZrpgW99q17VZVL
Generated by Claude Code