Commit 4e75505a authored by Kenton Varda's avatar Kenton Varda

Fix regression in JSON annotations when flattening a non-group struct.

(Also make sure that external struct-unions are tested.)
parent 960fb926
......@@ -844,10 +844,12 @@ R"({ "names-can_contain!anything Really": "foo",
"testBase64": "ZnJlZA==",
"testHex": "706c756768",
"bUnion": "renamed-bar",
"bValue": 678 })"_kj;
"bValue": 678,
"externalUnion": {"type": "bar", "value": "cba"} })"_kj;
static constexpr kj::StringPtr GOLDEN_ANNOTATED_REVERSE =
R"({
"externalUnion": {"type": "bar", "value": "cba"},
"bValue": 678,
"bUnion": "renamed-bar",
"testHex": "706c756768",
......@@ -940,6 +942,8 @@ KJ_TEST("rename fields") {
root.getBUnion().setBar(678);
root.initExternalUnion().initBar().setValue("cba");
auto encoded = json.encode(root.asReader());
KJ_EXPECT(encoded == GOLDEN_ANNOTATED, encoded);
......
......@@ -82,6 +82,8 @@ struct TestJsonAnnotations {
foo @20 :Text;
bar @21 :UInt32 $Json.name("renamed-bar");
}
externalUnion @22 :TestJsonAnnotations3;
}
struct TestJsonAnnotations2 {
......@@ -89,6 +91,17 @@ struct TestJsonAnnotations2 {
cycle @1 :TestJsonAnnotations;
}
struct TestJsonAnnotations3 $Json.discriminator(name = "type") {
union {
foo @0 :UInt32;
bar @1 :TestFlattenedStruct $Json.flatten();
}
}
struct TestFlattenedStruct {
value @0 :Text;
}
enum TestJsonAnnotatedEnum {
foo @0;
bar @1 $Json.name("renamed-bar");
......
......@@ -1014,6 +1014,11 @@ public:
if (flattened) {
info.flattenHandler = subHandler;
}
} else if (type.isStruct()) {
if (flattened) {
info.flattenHandler = codec.loadAnnotatedHandler(
type.asStruct(), nullptr, nullptr, dependencies);
}
}
bool isUnionMember = fieldProto.getDiscriminantValue() != schema::Field::NO_DISCRIMINANT;
......
......@@ -17,4 +17,5 @@
"testBase64": "ZnJlZA==",
"testHex": "706c756768",
"bUnion": "renamed-bar",
"bValue": 678 }
"bValue": 678,
"externalUnion": {"type": "bar", "value": "cba"} }
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