Test custom converter for char (#1963)

This commit is contained in:
Benoit Blanchon
2023-08-24 09:43:23 +02:00
parent 9794ba24b2
commit aebf042bae

View File

@ -158,6 +158,11 @@ void convertToJson(char c, JsonVariant var) {
char buf[] = {c, 0};
var.set(buf);
}
void convertFromJson(JsonVariantConst src, char& dst) {
auto p = src.as<const char*>();
dst = p ? p[0] : 0;
}
} // namespace ArduinoJson
TEST_CASE("Convert char to string") { // issue #1922
@ -165,3 +170,9 @@ TEST_CASE("Convert char to string") { // issue #1922
doc.set('a');
REQUIRE(doc.as<std::string>() == "a");
}
TEST_CASE("Convert string to char") { // issue #1963
StaticJsonDocument<64> doc;
doc.set("a");
REQUIRE(doc.as<char>() == 'a');
}