Skip to content

Commit fa878e6

Browse files
committedOct 21, 2020
Allow enum as top level parameter in procedure calls (fixes #10)
1 parent 4aa83f1 commit fa878e6

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed
 

‎CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.2.1] - 2020-10-21
9+
### Changed
10+
- Updated Catch to version 2.13.2
11+
- Updated nlohmann_json to 3.9.1
12+
13+
### Fixed
14+
- Typemapper failed to convert enum parameters on top-level (#10)
15+
816
## [0.2.0] - 2020-10-14
917

1018
### Added

‎include/jsonrpccxx/typemapper.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ namespace jsonrpccxx {
2222
}
2323
template <typename T>
2424
constexpr json::value_t GetType(type<T>) {
25+
if (std::is_enum<T>::value) {
26+
return json::value_t::string;
27+
}
2528
return json::value_t::object;
2629
}
2730
constexpr json::value_t GetType(type<void>) { return json::value_t::null; }

‎test/typemapper.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,21 @@ bool add_products(const vector<product> &products) {
146146
return true;
147147
}
148148

149+
string enumToString(const category& category) {
150+
switch (category) {
151+
case category::cash_carry: return "cash&carry";
152+
case category::order: return "online-order";
153+
default: return "unknown category";
154+
}
155+
}
156+
157+
TEST_CASE("test with enum as top level parameter", TEST_MODULE) {
158+
MethodHandle mh = GetHandle(&enumToString);
159+
160+
json params = R"(["cc"])"_json;
161+
CHECK(mh(params) == "cash&carry");
162+
}
163+
149164
TEST_CASE("test with custom params", TEST_MODULE) {
150165
MethodHandle mh = GetHandle(&add_products);
151166
catalog.clear();

0 commit comments

Comments
 (0)