core-adapters 0.1.3
Third-party adapters for snicholls-core: nanobind helpers, nlohmann/json hooks, the snicholls_core Python package
Loading...
Searching...
No Matches
secret_json.hpp
Go to the documentation of this file.
1//
2// secret_json.hpp
3// core-adapters
4//
5// Copyright 2010-2026 Saxon Herschel Nicholls
6//
7
49
50#ifndef snicholls_core_adapters_nlohmann_secret_json_hpp
51#define snicholls_core_adapters_nlohmann_secret_json_hpp
52
53#include <string>
54#include <utility>
55
57#include <snicholls/core/secret.hpp>
58
59namespace snicholls {
60
67template <typename T>
68void from_json(const nlohmann::json& j, secret<T>& s)
69{
70 T value{};
71 try {
72 j.get_to(value);
73 } catch (const nlohmann::json::exception&) {
74 // Translated without nlohmann's message: it can quote the value.
75 std::string what("snicholls::secret from_json: the value does not convert to the secret's type (got ");
76 what += j.type_name();
77 what += ')';
78 throw json_error(what);
79 }
80 s = secret<T>(std::move(value));
81}
82
83} // namespace snicholls
84
85#endif /* snicholls_core_adapters_nlohmann_secret_json_hpp */
void from_json(const nlohmann::json &j, decimal &d)
Reads canonical decimal text from a JSON string.
snicholls::json_error and the nlohmann/json adapter layer: shared by every adapter.
A JSON value that does not convert to or from a core type.
Definition json.hpp:76