diff --git a/JsonGenerator/JsonValue.h b/JsonGenerator/JsonValue.h index 12b491df..3ba9e2d7 100644 --- a/JsonGenerator/JsonValue.h +++ b/JsonGenerator/JsonValue.h @@ -69,6 +69,11 @@ namespace ArduinoJson return ""; } + operator double() + { + return content.asDouble; + } + operator int() { return content.asLong; diff --git a/JsonGeneratorTests/JsonValue_Cast_Tests.cpp b/JsonGeneratorTests/JsonValue_Cast_Tests.cpp index 3bbd73a7..591cb690 100644 --- a/JsonGeneratorTests/JsonValue_Cast_Tests.cpp +++ b/JsonGeneratorTests/JsonValue_Cast_Tests.cpp @@ -19,9 +19,15 @@ namespace JsonGeneratorTests public: - TEST_METHOD(String) - { - setValueAndCheckCast("hello"); + TEST_METHOD(Bool) + { + setValueAndCheckCast(true); + setValueAndCheckCast(false); + } + + TEST_METHOD(Double) + { + setValueAndCheckCast(3.14156); } TEST_METHOD(Integer) @@ -34,10 +40,9 @@ namespace JsonGeneratorTests setValueAndCheckCast(42L); } - TEST_METHOD(Bool) + TEST_METHOD(String) { - setValueAndCheckCast(true); - setValueAndCheckCast(false); + setValueAndCheckCast("hello"); } private: