• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Thalhammer / jwt-cpp / 22888341482

10 Mar 2026 05:19AM UTC coverage: 91.528% (-0.8%) from 92.343%
22888341482

push

github

web-flow
:mirror: Add support for reflect-cpp's JSON (#421)

* add reflect json traits

* jwt-cpp defaults

* fix clang tidy warnings

* fix clang tidy warnings

* rename directory

* add tests

* add tests

* add tests

* replace unnecessary copy with move

* gate reflect cpp tests behind flag

* reflect cpp CI work

* reflect-cpp example

* reflect-cpp CI

* reflect-cpp CI

* match naming + update ci

* first pass code review

* linter

* linter

* align naming

* make file +x

* align target name

fix order or targets in tests

* fix typo

* Fix target_link_libraries syntax for jwt-cpp

* cleanup example code

* add reflect-json to coverage tests

---------

Co-authored-by: Ali Girayhan Ozbay <aligirayhan.ozbay@abex.capital>
Co-authored-by: Ali Girayhan Ă–zbay <aligirayhan@ozbay.org>

27 of 43 new or added lines in 1 file covered. (62.79%)

1426 of 1558 relevant lines covered (91.53%)

687.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.79
/include/jwt-cpp/traits/reflectcpp-json/traits.h
1
#ifndef JWT_CPP_REFLECT_CPP_TRAITS_H
2
#define JWT_CPP_REFLECT_CPP_TRAITS_H
3

4
#ifndef JWT_DISABLE_PICOJSON
5
#define JWT_DISABLE_PICOJSON
6
#endif
7

8
#include "jwt-cpp/jwt.h"
9

10
#include <rfl/Generic.hpp>
11
#include <rfl/json.hpp>
12
#include <variant>
13

14
namespace jwt::traits {
15

16
        struct reflectcpp_json {
17

18
                using value_type = rfl::Generic;
19
                using object_type = rfl::Generic::Object;
20
                using array_type = rfl::Generic::Array;
21
                using string_type = std::string;
22
                using number_type = double;
23
                using integer_type = int64_t;
24
                using boolean_type = bool;
25

26
                template<class... Ts>
27
                struct variant_overloaded : Ts... {
28
                        using Ts::operator()...;
29
                };
30

31
                static jwt::json::type get_type(const value_type& val) {
34✔
32
                        return std::visit(
34✔
33
                                variant_overloaded{
34✔
NEW
34
                                        [](boolean_type const&) -> jwt::json::type { return jwt::json::type::boolean; },
×
35
                                        [](integer_type const&) -> jwt::json::type { return jwt::json::type::integer; },
9✔
NEW
36
                                        [](number_type const&) -> jwt::json::type { return jwt::json::type::number; },
×
37
                                        [](string_type const&) -> jwt::json::type { return jwt::json::type::string; },
17✔
38
                                        [](array_type const&) -> jwt::json::type { return jwt::json::type::array; },
4✔
39
                                        [](object_type const&) -> jwt::json::type { return jwt::json::type::object; },
4✔
NEW
40
                                        [](std::nullopt_t const&) -> jwt::json::type { throw std::logic_error("invalid type"); },
×
41
                                },
42
                                val.get());
102✔
43
                }
44

45
                static object_type as_object(const value_type& val) {
14✔
46
                        const auto& variant = val.get();
14✔
47
                        if (!std::holds_alternative<object_type>(variant)) throw std::bad_cast();
14✔
48
                        return std::get<object_type>(variant);
14✔
49
                }
50

NEW
51
                static array_type as_array(const value_type& val) {
×
NEW
52
                        const auto& variant = val.get();
×
NEW
53
                        if (!std::holds_alternative<array_type>(variant)) throw std::bad_cast();
×
NEW
54
                        return std::get<array_type>(variant);
×
55
                }
56

57
                static string_type as_string(const value_type& val) {
20✔
58
                        const auto& variant = val.get();
20✔
59
                        if (!std::holds_alternative<string_type>(variant)) throw std::bad_cast();
20✔
60
                        return std::get<string_type>(variant);
20✔
61
                }
62

63
                static integer_type as_integer(const value_type& val) {
8✔
64
                        const auto& variant = val.get();
8✔
65
                        if (!std::holds_alternative<integer_type>(variant)) throw std::bad_cast();
8✔
66
                        return std::get<integer_type>(variant);
8✔
67
                }
68

NEW
69
                static boolean_type as_boolean(const value_type& val) {
×
NEW
70
                        const auto& variant = val.get();
×
NEW
71
                        if (!std::holds_alternative<boolean_type>(variant)) throw std::bad_cast();
×
NEW
72
                        return std::get<boolean_type>(variant);
×
73
                }
74

NEW
75
                static number_type as_number(const value_type& val) {
×
NEW
76
                        const auto& variant = val.get();
×
NEW
77
                        if (!std::holds_alternative<number_type>(variant)) throw std::bad_cast();
×
NEW
78
                        return std::get<number_type>(variant);
×
79
                }
80

81
                static bool parse(value_type& out, string_type const& json) {
16✔
82
                        auto res = rfl::json::read<rfl::Generic>(json);
16✔
83
                        if (res) {
16✔
84
                                out = *std::move(res);
16✔
85
                                return true;
16✔
86
                        }
NEW
87
                        return false;
×
88
                }
16✔
89

90
                static std::string serialize(const value_type& val) { return rfl::json::write(val); }
14✔
91
        };
92

93
} // namespace jwt::traits
94

95
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc