Repository navigation
fix(kv): serialize maps as objects in KvStore::put - #1094
Open
PedroRosalba wants to merge 1 commit into
Open
PedroRosalba wants to merge 1 commit into
PedroRosalba wants to merge 1 commit into
Conversation
KvStore::put serializes any non-string value with
serde_wasm_bindgen::to_value and then JSON.stringify, but the default
serializer writes Rust maps (HashMap, BTreeMap, serde_json::Value::Object)
as JS Map and byte buffers as Uint8Array. JSON.stringify encodes a Map as
{} and a Uint8Array as an object keyed by index, so every map-typed field
is silently stored as {} and cannot be read back.
Serialize the value with serialize_maps_as_objects and
serialize_bytes_as_arrays, as the builder options already do. Strings,
numbers and booleans take the same short-circuits as before. Add a test
that puts a struct with a HashMap and a serde_json::Value field and checks
both the Rust round-trip and the raw stored JSON.
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.
Problem
KvStore::putserializes any non-string value withserde_wasm_bindgen::to_valueand thenJSON.stringify. The default serializer writes Rust maps (HashMap,BTreeMap,serde_json::Value::Object) as a JSMapand byte buffers as aUint8Array;JSON.stringifyturns aMapinto{}and aUint8Arrayinto an object keyed by index. Every map-typed field is silently stored as{}and cannot be read back.Same root cause as the queue producer fix in the sibling PR for
Queue::send.Fix
Serialize with
serialize_maps_as_objects(true)andserialize_bytes_as_arrays(true), which is what the builder options in the same module already do. Strings, numbers and booleans keep their existing short-circuits.Tests
Puts a struct with a
HashMapand aserde_json::Valuefield, then checks both the Rust round-trip and the raw stored JSON text. Fails onmain, passes with this change; full suite green.Tested on macOS (Apple Silicon) only.