Unverified Commit 5c16ad4b authored by Kenton Varda's avatar Kenton Varda Committed by GitHub

Merge pull request #744 from capnproto/fix-json-field-handler-in-union

Fix JSON field handlers not triggering on union members of annotated types.
parents 7bc23808 6d765ffe
......@@ -975,6 +975,21 @@ KJ_TEST("rename fields") {
}
}
KJ_TEST("base64 union encoded correctly") {
// At one point field handlers were not correctly applied when the field was a member of a union
// in a type that was handled by annotation.
JsonCodec json;
json.handleByAnnotation<TestBase64Union>();
json.setPrettyPrint(true);
MallocMessageBuilder message;
auto root = message.getRoot<TestBase64Union>();
root.initFoo(5);
KJ_EXPECT(json.encode(root) == "{\"foo\": \"AAAAAAA=\"}", json.encode(root));
}
} // namespace
} // namespace _ (private)
} // namespace capnp
......@@ -114,3 +114,10 @@ enum TestJsonAnnotatedEnum {
baz @2 $Json.name("renamed-baz");
qux @3;
}
struct TestBase64Union {
union {
foo @0 :Data $Json.base64;
bar @1 :Text;
}
}
......@@ -1255,7 +1255,7 @@ private:
// When we have an explicit union discriminant, we don't need to encode void fields.
} else {
flattenedFields.add(FlattenedField {
prefix, info.name, which->getType(), reader.get(*which) });
prefix, info.name, *which, reader.get(*which) });
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment