1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 03:37:45 +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

@ -2,6 +2,7 @@
#include <AK/JsonObject.h>
#include <AK/JsonValue.h>
#include <AK/LogStream.h>
#include <AK/StringBuilder.h>
#include <LibCore/CFile.h>
#include <stdio.h>
@ -70,7 +71,7 @@ int main(int argc, char** argv)
auto class_name = widget_object.get("class").to_string();
dbg() << " " << name << " = new " << class_name << "(main_widget);";
widget_object.for_each_member([&](auto& property_name, auto& property_value) {
widget_object.for_each_member([&](auto& property_name, const JsonValue& property_value) {
if (property_name == "class")
return;
@ -79,7 +80,7 @@ int main(int argc, char** argv)
if (property_value.is_null())
value = "{}";
else
value = property_value.serialized();
value = property_value.to_string();
dbg() << " " << name << "->set_" << property_name << "(" << value << ");";
});

View file

@ -4,6 +4,7 @@
#include "VBWidgetRegistry.h"
#include <AK/JsonArray.h>
#include <AK/JsonObject.h>
#include <AK/StringBuilder.h>
#include <LibCore/CFile.h>
#include <LibGUI/GAction.h>
#include <LibGUI/GMenu.h>
@ -318,7 +319,7 @@ void VBForm::load_from_file(const String& path)
(void)property_name;
(void)property_value;
VBProperty& property = vbwidget->property(property_name);
dbgprintf("Set property %s.%s to '%s'\n", widget_class.characters(), property_name.characters(), property_value.serialized().characters());
dbgprintf("Set property %s.%s to '%s'\n", widget_class.characters(), property_name.characters(), property_value.to_string().characters());
property.set_value(property_value);
});
m_widgets.append(vbwidget);
@ -349,7 +350,7 @@ void VBForm::write_to_file(const String& path)
widget_array.append(widget_object);
}
form_object.set("widgets", widget_array);
file.write(form_object.serialized());
file.write(form_object.to_string());
}
void VBForm::dump()