|
iceberg-cpp
|
Internal utilities for JSON serialization and deserialization. More...
#include <optional>#include <nlohmann/json.hpp>#include "iceberg/result.h"#include "iceberg/util/macros.h"Go to the source code of this file.
Functions | |
| template<typename T > | |
| void | iceberg::SetOptionalField (nlohmann::json &json, std::string_view key, const std::optional< T > &value) |
|
template<typename T > requires requires(const T& t) { t.empty(); } | |
| void | iceberg::SetContainerField (nlohmann::json &json, std::string_view key, const T &value) |
| void | iceberg::SetOptionalStringField (nlohmann::json &json, std::string_view key, const std::string &value) |
| std::string | iceberg::SafeDumpJson (const nlohmann::json &json) |
| template<typename T > | |
| Result< T > | iceberg::GetTypedJsonValue (const nlohmann::json &json) |
| template<typename T > | |
| Result< T > | iceberg::GetJsonValueImpl (const nlohmann::json &json, std::string_view key) |
| template<typename T > | |
| Result< std::optional< T > > | iceberg::GetJsonValueOptional (const nlohmann::json &json, std::string_view key) |
| template<typename T > | |
| Result< T > | iceberg::GetJsonValue (const nlohmann::json &json, std::string_view key) |
| template<typename T > | |
| Result< T > | iceberg::GetJsonValueOrDefault (const nlohmann::json &json, std::string_view key, T default_value=T{}) |
| template<typename T > | |
| nlohmann::json::array_t | iceberg::ToJsonList (const std::vector< T > &list) |
| Convert a list of items to a json array. | |
| template<typename T > | |
| nlohmann::json::array_t | iceberg::ToJsonList (const std::vector< std::shared_ptr< T > > &list) |
| Overload of the above function for a list of shared pointers. | |
| template<typename T > | |
| Result< std::vector< T > > | iceberg::FromJsonList (const nlohmann::json &json, std::string_view key, const std::function< Result< T >(const nlohmann::json &)> &from_json) |
| Parse a list of items from a JSON object. | |
| template<typename T > | |
| Result< std::vector< std::shared_ptr< T > > > | iceberg::FromJsonList (const nlohmann::json &json, std::string_view key, const std::function< Result< std::shared_ptr< T > >(const nlohmann::json &)> &from_json) |
| Parse a list of items from a JSON object. | |
| template<typename T > | |
| nlohmann::json::object_t | iceberg::ToJsonMap (const std::unordered_map< std::string, T > &map) |
| Convert a map of type <std::string, T> to a json object. | |
| template<typename T > | |
| nlohmann::json::object_t | iceberg::ToJsonMap (const std::unordered_map< std::string, std::shared_ptr< T > > &map) |
| Overload of the above function for a map of type <std::string, std::shared_ptr<T>>. | |
| template<typename T = std::string> | |
| Result< std::unordered_map< std::string, T > > | iceberg::FromJsonMap (const nlohmann::json &json, std::string_view key, const std::function< Result< T >(const nlohmann::json &)> &from_json=[](const nlohmann::json &json) -> Result< T > { static_assert(std::is_same_v< T, std::string >, "T must be std::string");try { return json.get< std::string >();} catch(const std::exception &ex) { return JsonParseError("Cannot parse {} to a string value: {}", SafeDumpJson(json), ex.what());} }) |
| Parse a map of type <std::string, T> from a JSON object. | |
Internal utilities for JSON serialization and deserialization.
| Result< std::vector< std::shared_ptr< T > > > iceberg::FromJsonList | ( | const nlohmann::json & | json, |
| std::string_view | key, | ||
| const std::function< Result< std::shared_ptr< T > >(const nlohmann::json &)> & | from_json | ||
| ) |
Parse a list of items from a JSON object.
| [in] | json | The JSON object to parse. |
| [in] | key | The key to parse. |
| [in] | from_json | The function to parse an item from a JSON object. |
| Result< std::vector< T > > iceberg::FromJsonList | ( | const nlohmann::json & | json, |
| std::string_view | key, | ||
| const std::function< Result< T >(const nlohmann::json &)> & | from_json | ||
| ) |
Parse a list of items from a JSON object.
| [in] | json | The JSON object to parse. |
| [in] | key | The key to parse. |
| [in] | from_json | The function to parse an item from a JSON object. |
| Result< std::unordered_map< std::string, T > > iceberg::FromJsonMap | ( | const nlohmann::json & | json, |
| std::string_view | key, | ||
| const std::function< Result< T >(const nlohmann::json &)> & | from_json = [](const nlohmann::json& json) -> Result<T> { static_assert(std::is_same_v<T, std::string>, "T must be std::string"); try { return json.get<std::string>(); } catch (const std::exception& ex) { return JsonParseError("Cannot parse {} to a string value: {}", SafeDumpJson(json), ex.what()); } } |
||
| ) |
Parse a map of type <std::string, T> from a JSON object.
| [in] | json | The JSON object to parse. |
| [in] | key | The key to parse. |
| [in] | from_json | The function to parse an item from a JSON object. |
| nlohmann::json::array_t iceberg::ToJsonList | ( | const std::vector< T > & | list | ) |
Convert a list of items to a json array.
Note that ToJson(const T&) is required for this function to work.
| nlohmann::json::object_t iceberg::ToJsonMap | ( | const std::unordered_map< std::string, T > & | map | ) |
Convert a map of type <std::string, T> to a json object.
Note that ToJson(const T&) is required for this function to work.