Skip to content

Commit 00fc055

Browse files
committed
Add type & value fields to primitive json types
This aligns with how custom types are exported to JSON.
1 parent ddc958e commit 00fc055

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/json_export.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,28 @@ bool JsonExporter::toJson(const Any& any, nlohmann::json& dst) const
1414
nlohmann::json json;
1515
auto const& type = any.castedType();
1616

17+
const std::string type_field = "__type";
18+
const std::string value_field = "value";
19+
1720
if(any.isString())
1821
{
19-
dst = any.cast<std::string>();
22+
dst[type_field] = "string";
23+
dst[value_field] = any.cast<std::string>();
2024
}
2125
else if(type == typeid(int64_t))
2226
{
23-
dst = any.cast<int64_t>();
27+
dst[type_field] = "int64_t";
28+
dst[value_field] = any.cast<int64_t>();
2429
}
2530
else if(type == typeid(uint64_t))
2631
{
27-
dst = any.cast<uint64_t>();
32+
dst[type_field] = "uint64_t";
33+
dst[value_field] = any.cast<uint64_t>();
2834
}
2935
else if(type == typeid(double))
3036
{
31-
dst = any.cast<double>();
37+
dst[type_field] = "double";
38+
dst[value_field] = any.cast<double>();
3239
}
3340
else
3441
{

0 commit comments

Comments
 (0)