Compare commits

..

5 Commits

11 changed files with 87 additions and 6 deletions

View File

@ -1,6 +1,12 @@
ArduinoJson: change log
=======================
v5.0.3
------
* Fixed `printTo(String)` which wrote numbers instead of strings (issue #120)
* Fixed return type of `JsonArray::is<T>()` and some others (issue #121)
v5.0.2
------

View File

@ -78,6 +78,14 @@ From GitHub user `zacsketches`:
> I've been watching you consistently develop this library over the past six months, and I used it today for a publish and subscribe architecture designed to help hobbyists move into more advanced robotics. Your library allowed me to implement remote subscription in order to facilitate multi-processor robots.
> ArduinoJson saved me a week's worth of time!!
[From Reddit user `erm_what_`](https://www.reddit.com/r/arduino/comments/3jj6ep/announcing_arduinojson_50/cusjk8c):
> This is a great library and I wouldn't be able to do the project I'm doing without it. I completely recommend it.
[From Reddit user `makerhacks`](https://www.reddit.com/r/arduino/comments/3jj6ep/announcing_arduinojson_50/cusqg7b):
> I am just starting an ESP8266 clock project and now I can output JSON from my server script and interpret it painlessly.
---
Found this library useful? Please star this project or [help me back with a donation!](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=donate%40benoitblanchon%2efr&lc=GB&item_name=Benoit%20Blanchon&item_number=Arduino%20JSON&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted) :smile:

View File

@ -18,7 +18,8 @@ class DynamicStringBuilder : public Print {
DynamicStringBuilder(String &str) : _str(str) {}
virtual size_t write(uint8_t c) {
_str += c;
// Need to cast to char, otherwise String will print a number (issue #120)
_str += static_cast<char>(c);
return 1;
}

View File

@ -92,7 +92,7 @@ class JsonArray : public Internals::JsonPrintable<JsonArray>,
// Check the type of the value at specified index.
template <typename T>
FORCE_INLINE T is(size_t index) const;
FORCE_INLINE bool is(size_t index) const;
// Creates a JsonArray and adds a reference at the end of the array.
// It's a shortcut for JsonBuffer::createArray() and JsonArray::add()

View File

@ -182,7 +182,7 @@ inline T JsonArray::get(size_t index) const {
}
template <typename T>
inline T JsonArray::is(size_t index) const {
inline bool JsonArray::is(size_t index) const {
node_type *node = getNodeAt(index);
return node ? node->content.is<T>() : false;
}

View File

@ -26,7 +26,7 @@ class JsonArraySubscript : public JsonSubscriptBase<JsonArraySubscript> {
}
template <typename T>
FORCE_INLINE T is() const {
FORCE_INLINE bool is() const {
return _array.is<T>(_index);
}

View File

@ -29,7 +29,7 @@ class JsonObjectSubscript
}
template <typename TValue>
FORCE_INLINE TValue is() const {
FORCE_INLINE bool is() const {
return _object.is<TValue>(_key);
}

View File

@ -1,5 +1,5 @@
name=ArduinoJson
version=5.0.2
version=5.0.3
author=Benoit Blanchon <blog.benoitblanchon.fr>
maintainer=Benoit Blanchon <blog.benoitblanchon.fr>
sentence=An efficient and elegant JSON library for Arduino.

View File

@ -0,0 +1,52 @@
#!/bin/bash
TAG=$(git describe)
OUTPUT="ArduinoJson-$TAG-old-layout.zip"
cd $(dirname $0)/..
cat > ArduinoJson.h <<END
// WARNING:
// --------
// This file is a workaround for old version of the Arduino IDE.
// If you are using Arduino IDE 1.0.6 or above, then you installed the wrong
// package of ArduinoJson.
// In that case, just delete the current installation and install the package.
END
cp ArduinoJson.h ArduinoJson.cpp
cat "include/ArduinoJson.h" | sed 's!include "!include "include/!g' >> ArduinoJson.h
find src -name "*.cpp" |
while read FILE; do
echo >> ArduinoJson.cpp
echo "// $FILE" >> ArduinoJson.cpp
echo "//" >> ArduinoJson.cpp
cat "$FILE" | sed 's!\.\./!!g' >> ArduinoJson.cpp
done
unix2dos ArduinoJson.cpp
unix2dos ArduinoJson.h
pushd ..
# remove existing file
rm -f $OUTPUT
# create zipman dos2
7z a $OUTPUT \
ArduinoJson/CHANGELOG.md \
ArduinoJson/examples \
ArduinoJson/include/ArduinoJson \
ArduinoJson/keywords.txt \
ArduinoJson/LICENSE.md \
ArduinoJson/README.md \
ArduinoJson/ArduinoJson.h \
ArduinoJson/ArduinoJson.cpp \
-x!ArduinoJson/src/CMakeLists.txt
popd
rm ArduinoJson.h
rm ArduinoJson.cpp

View File

@ -39,11 +39,13 @@ class JsonArray_Container_Tests : public ::testing::Test {
private:
template <typename T>
void itemMustEqual(int index, T expected) {
EXPECT_TRUE(_array[index].is<T>());
EXPECT_EQ(expected, _array[index].as<T>());
}
template <typename T>
void itemMustReference(int index, const T& expected) {
EXPECT_TRUE(_array[index].is<T&>());
EXPECT_EQ(&expected, &_array[index].as<T&>());
}
};

View File

@ -61,6 +61,8 @@ TEST_F(JsonObject_Container_Tests, CanStoreIntegers) {
_object["hello"] = 123;
_object.set("world", 456);
EXPECT_TRUE(_object["hello"].is<int>());
EXPECT_FALSE(_object["hello"].is<double>());
EXPECT_EQ(123, _object["hello"].as<int>());
EXPECT_EQ(456, _object["world"].as<int>());
}
@ -69,6 +71,8 @@ TEST_F(JsonObject_Container_Tests, CanStoreDoubles) {
_object["hello"] = 123.45;
_object.set("world", 456.78);
EXPECT_TRUE(_object["hello"].is<double>());
EXPECT_FALSE(_object["hello"].is<long>());
EXPECT_EQ(123.45, _object["hello"].as<double>());
EXPECT_EQ(456.78, _object["world"].as<double>());
}
@ -77,6 +81,8 @@ TEST_F(JsonObject_Container_Tests, CanStoreBooleans) {
_object["hello"] = true;
_object.set("world", false);
EXPECT_TRUE(_object["hello"].is<bool>());
EXPECT_FALSE(_object["hello"].is<long>());
EXPECT_TRUE(_object["hello"].as<bool>());
EXPECT_FALSE(_object["world"].as<bool>());
}
@ -85,6 +91,8 @@ TEST_F(JsonObject_Container_Tests, CanStoreStrings) {
_object["hello"] = "h3110";
_object.set("world", "w0r1d");
EXPECT_TRUE(_object["hello"].is<const char*>());
EXPECT_FALSE(_object["hello"].is<long>());
EXPECT_STREQ("h3110", _object["hello"].as<const char*>());
EXPECT_STREQ("w0r1d", _object["world"].as<const char*>());
}
@ -96,6 +104,8 @@ TEST_F(JsonObject_Container_Tests, CanStoreArrays) {
_object["hello"] = array1;
_object.set("world", array2);
EXPECT_TRUE(_object["hello"].is<JsonArray&>());
EXPECT_FALSE(_object["hello"].is<JsonObject&>());
EXPECT_EQ(&array1, &_object["hello"].asArray());
EXPECT_EQ(&array2, &_object["world"].asArray());
}
@ -107,6 +117,8 @@ TEST_F(JsonObject_Container_Tests, CanStoreObjects) {
_object["hello"] = object1;
_object.set("world", object2);
EXPECT_TRUE(_object["hello"].is<JsonObject&>());
EXPECT_FALSE(_object["hello"].is<JsonArray&>());
EXPECT_EQ(&object1, &_object["hello"].asObject());
EXPECT_EQ(&object2, &_object["world"].asObject());
}