1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:54:58 +00:00

JSON: Templatize the JSON serialization code

This makes it possible to use something other than a StringBuilder for
serialization (and to produce something other than a String.) :^)
This commit is contained in:
Andreas Kling 2019-08-07 21:28:07 +02:00
parent 43ec733b61
commit f6998b1817
11 changed files with 145 additions and 109 deletions

View file

@ -3,28 +3,4 @@
namespace AK {
void JsonObject::serialize(StringBuilder& builder) const
{
int index = 0;
builder.append('{');
for_each_member([&] (auto& key, auto& value) {
builder.append('"');
builder.append(key);
builder.append('"');
builder.append(':');
value.serialize(builder);
if (index != size() - 1)
builder.append(',');
++index;
});
builder.append('}');
}
String JsonObject::serialized() const
{
StringBuilder builder;
serialize(builder);
return builder.to_string();
}
}