feature: Add Weaver[Any] support for Map[String, Any] serialization#368
feature: Add Weaver[Any] support for Map[String, Any] serialization#368
Conversation
Add AnyWeaver to support serialization of generic collections like Map[String, Any] and Seq[Any], similar to airframe-codec's AnyCodec. Key features: - Runtime type matching for primitives, collections, and enums - knownWeavers parameter for registering custom type weavers - Falls back to toString for unknown types Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary of ChangesHello @xerial, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces AnyWeaver for serializing generic collections like Map[String, Any], which is a great addition. The implementation is comprehensive, covering primitives, collections, and custom types via knownWeavers. The test suite is also thorough and covers many edge cases.
I've found one high-severity bug in the error handling logic within AnyWeaverImpl's unpackMap method, which could lead to errors when unpacking malformed map data. I've also left a minor comment on the design document to improve its reusability for other developers.
Overall, this is a solid feature implementation. Once the identified issue is addressed, it should be ready for merging.
| while i < len do | ||
| u.skipValue | ||
| u.skipValue | ||
| i += 1 |
There was a problem hiding this comment.
There's a bug in the error handling logic when unpacking a map key. If unpack(u, keyContext) fails, the unpacker's position will be at the corresponding value of the failed key. The current loop while i < len do ... attempts to skip len - i full key-value pairs. This is one value too many and will likely cause an error by reading past the end of the map.
The logic should be to first skip the value of the current failed pair, and then skip the remaining full pairs.
u.skipValue // Skip value of the current pair
i += 1
while i < len do
u.skipValue // key
u.skipValue // value
i += 1| ## Verification | ||
|
|
||
| ```bash | ||
| cd /Users/leo/work/uni/.worktree/feature-weaver-any |
When key unpacking fails, skip only the current value (key already consumed) before skipping remaining pairs. This prevents misalignment of the unpacker. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary
AnyWeaverto support serialization of generic collections likeMap[String, Any]andSeq[Any]knownWeaversparameter for registering custom type weavers (similar to airframe-codec'sknownSurfaces)toStringfor unknown typesUsage Example
Test plan
🤖 Generated with Claude Code