summaryrefslogtreecommitdiff
path: root/AK/JsonObjectSerializer.h
AgeCommit message (Collapse)Author
2023-01-21Everywhere: Remove string.h include from AK/Traits.h and resolve falloutAndrew Kaster
A lot of places were relying on AK/Traits.h to give it strnlen, memcmp, memcpy and other related declarations. In the quest to remove inclusion of LibC headers from Kernel files, deal with all the fallout of this included-everywhere header including less things.
2022-12-06AK+Everywhere: Rename String to DeprecatedStringLinus Groh
We have a new, improved string type coming up in AK (OOM aware, no null state), and while it's going to use UTF-8, the name UTF8String is a mouthful - so let's free up the String name by renaming the existing class. Making the old one have an annoying name will hopefully also help with quick adoption :^)
2022-11-26AK: Make it possible to not `using` AK classes into the global namespaceAndreas Kling
This patch adds the `USING_AK_GLOBALLY` macro which is enabled by default, but can be overridden by build flags. This is a step towards integrating Jakt and AK types.
2022-11-01AK: Allow destruction of JsonObjectSerializer objects after errorsGunnar Beutner
Previously we'd VERIFY() that the user had called finish(). This makes the following code incorrect though: auto json = TRY(JsonObjectSerializer<>::try_create(builder)); TRY(json.add("total_time"sv, total_time_scheduled.total)); TRY(json.finish()); return ...; If the second TRY() returns early we'd fail at the VERIFY() call in the destructor. Calling finish() in the destructor - like we had done earlier - is also not helpful because we have no idea whether the builder is still valid. Plus we wouldn't be able to handle any errors for that call. Verifying that either finish() was called or an error occurred doesn't work either because the caller might have multiple Json*Serializer objects, e.g. when inserting a JSON array into a JSON object. Forcing the user to call finish() on their "main" object when a sub-object caused an error seems unnecessarily tedious.
2022-07-12Everywhere: Add sv suffix to strings relying on StringView(char const*)sin-ack
Each of these strings would previously rely on StringView's char const* constructor overload, which would call __builtin_strlen on the string. Since we now have operator ""sv, we can replace these with much simpler versions. This opens the door to being able to remove StringView(char const*). No functional changes.
2022-07-12Everywhere: Explicitly specify the size in StringView constructorssin-ack
This commit moves the length calculations out to be directly on the StringView users. This is an important step towards the goal of removing StringView(char const*), as it moves the responsibility of calculating the size of the string to the user of the StringView (which will prevent naive uses causing OOB access).
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-08AK: Add float support for JsonValue and JsonObjectSerializerVrins
2022-02-27Everywhere: Make JSON serialization fallibleIdan Horowitz
This allows us to eliminate a major source of infallible allocation in the Kernel, as well as lay down the groundwork for OOM fallibility in userland.
2021-11-11Everywhere: Pass AK::StringView by valueAndreas Kling
2021-09-06AK: Make Json{Array,Object}Serializer ignore append() return valuesAndreas Kling
This is in preparation for making KBufferBuilder::append() and friends return a KResult. Long-term we should come up with a solution that works for both kernel and userspace clients of the JSON API.
2021-06-30Kernel: Don't compile JsonValue & friends into the kernelAndreas Kling
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-09AK: Use StringBuilder::appendff() instead of appendf()Andreas Kling
2020-11-02AK+Kernel: Escape JSON keys & valuesAndreas Kling
Grab the escaping logic from JSON string value serialization and use it for serializing all keys and values. Fixes #3917.
2020-05-22AK: Make JsonValue and JsonObjectSerializer speak int/long/long longAndreas Kling
While width-oriented integer types are nicer from the programmer's perspective, we have to accept that C++ thinks in int/long/long long.
2020-03-31AK: A few JSON improvementsEmanuel Sprung
* Add double number to object serializer * Handle negative double numbers correctly * Handle \r and \n in quoted strings independently This improves the situation when keys contain \r or \n that currently has the effect that "a\rkey" and "a\nkey" in an JSON object are the same key value.
2020-02-08AK: Add JsonObjectSerializer::add(key, bool) overloadAndreas Kling
Without this, bools will get implicitly converted to integers, which is usually not what we want.
2020-02-01AK: Add some integer overloads to JsonObjectSerializerAndreas Kling
This avoids constructing a temporary JsonValue just to append an int.
2020-01-24Meta: Claim copyright for files created by meSergey Bugaev
This changes copyright holder to myself for the source code files that I've created or have (almost) completely rewritten. Not included are the files that were significantly changed by others even though it was me who originally created them (think HtmlView), or the many other files I've contributed code to.
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2019-09-04Json: Add serializer fast-path for string valuesAndreas Kling
Passing these through the generic JsonValue path was causing us to instantiate temporary JsonValues that incurred a heap allocation. This avoids that by adding specialized overloads for string types.
2019-08-27JSON: Add JSON serializersSergey Bugaev
These are two new types that allow serializing JSON on-the-fly as it's generated, without building the whole JSON in memory first.