ChimeraTK-DeviceAccess 03.26.00
Loading...
Searching...
No Matches
JsonExtensions.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#pragma once
4
5#include <nlohmann/json.hpp>
6
7#include <optional>
8
9namespace nlohmann {
10
11 template<typename T>
12 struct adl_serializer<std::optional<T>> {
13 static void to_json(json& j, const std::optional<T>& opt) {
14 if(opt.has_value()) {
15 j = *opt;
16 }
17 else {
18 j = nullptr;
19 }
20 }
21
22 static void from_json(const json& j, std::optional<T>& opt) {
23 if(j.is_null()) {
24 opt = std::nullopt;
25 }
26 else {
27 opt = j.get<T>();
28 }
29 }
30 };
31
32} // namespace nlohmann
nlohmann::json json
STL namespace.
static void to_json(json &j, const std::optional< T > &opt)
static void from_json(const json &j, std::optional< T > &opt)