Coverage Report

Created: 2026-10-28 06:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/bmcweb/include/json_formatters.hpp
Line
Count
Source
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright OpenBMC Authors
3
#pragma once
4
5
#include <nlohmann/json.hpp>
6
7
#include <format>
8
9
// Clang-tidy would rather these be static, but using static causes the template
10
// specialization to not function.  Ignore the warning.
11
// NOLINTBEGIN(readability-convert-member-functions-to-static, cert-dcl58-cpp)
12
13
template <>
14
struct std::formatter<nlohmann::json::json_pointer>
15
{
16
    constexpr auto parse(std::format_parse_context& ctx)
17
0
    {
18
0
        return ctx.begin();
19
0
    }
20
    auto format(const nlohmann::json::json_pointer& ptr, auto& ctx) const
21
0
    {
22
0
        return std::format_to(ctx.out(), "{}", ptr.to_string());
23
0
    }
24
};
25
26
template <>
27
struct std::formatter<nlohmann::json>
28
{
29
    static constexpr auto parse(std::format_parse_context& ctx)
30
0
    {
31
0
        return ctx.begin();
32
0
    }
33
    auto format(const nlohmann::json& json, auto& ctx) const
34
    {
35
        return std::format_to(
36
            ctx.out(), "{}",
37
            json.dump(-1, ' ', false,
38
                      nlohmann::json::error_handler_t::replace));
39
    }
40
};
41
// NOLINTEND(readability-convert-member-functions-to-static, cert-dcl58-cpp)