mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-04 15:45:25 +00:00
AK+Everywhere: Convert JSON value serialization to String
This removes the use of StringBuilder::OutputType (which was ByteString, and only used by the JSON classes). And it removes the StringBuilder template parameter from the serialization methods; this was only ever used with StringBuilder, so a template is pretty overkill here.
This commit is contained in:
@@ -6,7 +6,9 @@
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "JsonObject.h"
|
||||
#include <AK/JsonObject.h>
|
||||
#include <AK/JsonObjectSerializer.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
|
||||
namespace AK {
|
||||
|
||||
@@ -275,4 +277,21 @@ bool JsonObject::remove(StringView key)
|
||||
return m_members.remove(key);
|
||||
}
|
||||
|
||||
String JsonObject::serialized() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
serialize(builder);
|
||||
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
void JsonObject::serialize(StringBuilder& builder) const
|
||||
{
|
||||
auto serializer = MUST(JsonObjectSerializer<>::try_create(builder));
|
||||
for_each_member([&](auto& key, auto& value) {
|
||||
MUST(serializer.add(key, value));
|
||||
});
|
||||
MUST(serializer.finish());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user