forked from bblanchon/ArduinoJson
Removed all deprecated features
This commit is contained in:
@ -16,6 +16,7 @@ HEAD
|
|||||||
* Removed `JsonBuffer::createArray()` and `createObject()`
|
* Removed `JsonBuffer::createArray()` and `createObject()`
|
||||||
* Removed `printTo()` and `prettyPrintTo()`
|
* Removed `printTo()` and `prettyPrintTo()`
|
||||||
* Removed `measureLength()` and `measurePrettyLength()`
|
* Removed `measureLength()` and `measurePrettyLength()`
|
||||||
|
* Removed all deprecated features
|
||||||
|
|
||||||
> ### BREAKING CHANGES
|
> ### BREAKING CHANGES
|
||||||
>
|
>
|
||||||
|
@ -130,11 +130,6 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Enable deprecated functions by default
|
|
||||||
#ifndef ARDUINOJSON_ENABLE_DEPRECATED
|
|
||||||
#define ARDUINOJSON_ENABLE_DEPRECATED 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Control the exponentiation threshold for big numbers
|
// Control the exponentiation threshold for big numbers
|
||||||
// CAUTION: cannot be more that 1e9 !!!!
|
// CAUTION: cannot be more that 1e9 !!!!
|
||||||
#ifndef ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD
|
#ifndef ARDUINOJSON_POSITIVE_EXPONENTIATION_THRESHOLD
|
||||||
|
@ -180,13 +180,6 @@ class JsonArray : public Internals::ReferenceType,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ARDUINOJSON_ENABLE_DEPRECATED
|
|
||||||
DEPRECATED("use remove() instead")
|
|
||||||
FORCE_INLINE void removeAt(size_t index) {
|
|
||||||
return remove(index);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <typename TValueRef>
|
template <typename TValueRef>
|
||||||
bool set_impl(size_t index, TValueRef value) {
|
bool set_impl(size_t index, TValueRef value) {
|
||||||
|
@ -73,14 +73,6 @@ class JsonArraySubscript : public JsonVariantBase<JsonArraySubscript> {
|
|||||||
FORCE_INLINE bool set(TValue* value) {
|
FORCE_INLINE bool set(TValue* value) {
|
||||||
return _array.set(_index, value);
|
return _array.set(_index, value);
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// bool set(TValue, uint8_t decimals);
|
|
||||||
// TValue = float, double
|
|
||||||
template <typename TValue>
|
|
||||||
DEPRECATED("Second argument is not supported anymore")
|
|
||||||
FORCE_INLINE bool set(const TValue& value, uint8_t) {
|
|
||||||
return _array.set(_index, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JsonArray& _array;
|
JsonArray& _array;
|
||||||
|
@ -24,25 +24,6 @@ class JsonObject;
|
|||||||
// fixed memory allocation.
|
// fixed memory allocation.
|
||||||
class JsonBuffer : Internals::NonCopyable {
|
class JsonBuffer : Internals::NonCopyable {
|
||||||
public:
|
public:
|
||||||
// Duplicates a string
|
|
||||||
//
|
|
||||||
// const char* strdup(TValue);
|
|
||||||
// TValue = const std::string&, const String&,
|
|
||||||
template <typename TString>
|
|
||||||
DEPRECATED("char* are duplicated, you don't need strdup() anymore")
|
|
||||||
typename Internals::EnableIf<!Internals::IsArray<TString>::value,
|
|
||||||
const char *>::type strdup(const TString &src) {
|
|
||||||
return Internals::StringTraits<TString>::duplicate(src, this);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// const char* strdup(TValue);
|
|
||||||
// TValue = char*, const char*, const FlashStringHelper*
|
|
||||||
template <typename TString>
|
|
||||||
DEPRECATED("char* are duplicated, you don't need strdup() anymore")
|
|
||||||
const char *strdup(TString *src) {
|
|
||||||
return Internals::StringTraits<TString *>::duplicate(src, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allocates n bytes in the JsonBuffer.
|
// Allocates n bytes in the JsonBuffer.
|
||||||
// Return a pointer to the allocated memory or NULL if allocation fails.
|
// Return a pointer to the allocated memory or NULL if allocation fails.
|
||||||
virtual void *alloc(size_t size) = 0;
|
virtual void *alloc(size_t size) = 0;
|
||||||
|
@ -112,29 +112,6 @@ class JsonObject : public Internals::ReferenceType,
|
|||||||
bool set(TString* key, TValue* value) {
|
bool set(TString* key, TValue* value) {
|
||||||
return set_impl<TString*, TValue*>(key, value);
|
return set_impl<TString*, TValue*>(key, value);
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// bool set(TKey, TValue, uint8_t decimals);
|
|
||||||
// TKey = const std::string&, const String&
|
|
||||||
// TValue = float, double
|
|
||||||
template <typename TValue, typename TString>
|
|
||||||
DEPRECATED("Second argument is not supported anymore")
|
|
||||||
typename Internals::EnableIf<Internals::IsFloatingPoint<TValue>::value,
|
|
||||||
bool>::type
|
|
||||||
set(const TString& key, TValue value, uint8_t) {
|
|
||||||
return set_impl<const TString&, const JsonVariant&>(key,
|
|
||||||
JsonVariant(value));
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// bool set(TKey, TValue, uint8_t decimals);
|
|
||||||
// TKey = char*, const char*, const FlashStringHelper*
|
|
||||||
// TValue = float, double
|
|
||||||
template <typename TValue, typename TString>
|
|
||||||
DEPRECATED("Second argument is not supported anymore")
|
|
||||||
typename Internals::EnableIf<Internals::IsFloatingPoint<TValue>::value,
|
|
||||||
bool>::type
|
|
||||||
set(TString* key, TValue value, uint8_t) {
|
|
||||||
return set_impl<TString*, const JsonVariant&>(key, JsonVariant(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gets the value associated with the specified key.
|
// Gets the value associated with the specified key.
|
||||||
//
|
//
|
||||||
|
@ -81,14 +81,6 @@ class JsonObjectSubscript
|
|||||||
FORCE_INLINE bool set(const TValue* value) {
|
FORCE_INLINE bool set(const TValue* value) {
|
||||||
return _object.set(_key, value);
|
return _object.set(_key, value);
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// bool set(TValue, uint8_t decimals);
|
|
||||||
// TValue = float, double
|
|
||||||
template <typename TValue>
|
|
||||||
DEPRECATED("Second argument is not supported anymore")
|
|
||||||
FORCE_INLINE bool set(const TValue& value, uint8_t) {
|
|
||||||
return _object.set(_key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JsonObject& _object;
|
JsonObject& _object;
|
||||||
|
@ -65,15 +65,6 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> {
|
|||||||
_type = JSON_FLOAT;
|
_type = JSON_FLOAT;
|
||||||
_content.asFloat = static_cast<JsonFloat>(value);
|
_content.asFloat = static_cast<JsonFloat>(value);
|
||||||
}
|
}
|
||||||
template <typename T>
|
|
||||||
DEPRECATED("Second argument is not supported anymore")
|
|
||||||
JsonVariant(T value, uint8_t,
|
|
||||||
typename Internals::EnableIf<
|
|
||||||
Internals::IsFloatingPoint<T>::value>::type * = 0) {
|
|
||||||
using namespace Internals;
|
|
||||||
_type = JSON_FLOAT;
|
|
||||||
_content.asFloat = static_cast<JsonFloat>(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a JsonVariant containing an integer value.
|
// Create a JsonVariant containing an integer value.
|
||||||
// JsonVariant(char)
|
// JsonVariant(char)
|
||||||
@ -355,14 +346,4 @@ class JsonVariant : public Internals::JsonVariantBase<JsonVariant> {
|
|||||||
// The various alternatives for the value of the variant.
|
// The various alternatives for the value of the variant.
|
||||||
Internals::JsonVariantContent _content;
|
Internals::JsonVariantContent _content;
|
||||||
};
|
};
|
||||||
|
|
||||||
DEPRECATED("Decimal places are ignored, use the float value instead")
|
|
||||||
inline JsonVariant float_with_n_digits(float value, uint8_t) {
|
|
||||||
return JsonVariant(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
DEPRECATED("Decimal places are ignored, use the double value instead")
|
|
||||||
inline JsonVariant double_with_n_digits(double value, uint8_t) {
|
|
||||||
return JsonVariant(value);
|
|
||||||
}
|
|
||||||
} // namespace ArduinoJson
|
} // namespace ArduinoJson
|
||||||
|
@ -13,23 +13,6 @@ namespace Internals {
|
|||||||
template <typename TImpl>
|
template <typename TImpl>
|
||||||
class JsonVariantCasts {
|
class JsonVariantCasts {
|
||||||
public:
|
public:
|
||||||
#if ARDUINOJSON_ENABLE_DEPRECATED
|
|
||||||
DEPRECATED("use as<JsonArray>() instead")
|
|
||||||
FORCE_INLINE JsonArray &asArray() const {
|
|
||||||
return impl()->template as<JsonArray>();
|
|
||||||
}
|
|
||||||
|
|
||||||
DEPRECATED("use as<JsonObject>() instead")
|
|
||||||
FORCE_INLINE JsonObject &asObject() const {
|
|
||||||
return impl()->template as<JsonObject>();
|
|
||||||
}
|
|
||||||
|
|
||||||
DEPRECATED("use as<char*>() instead")
|
|
||||||
FORCE_INLINE const char *asString() const {
|
|
||||||
return impl()->template as<const char *>();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Gets the variant as an array.
|
// Gets the variant as an array.
|
||||||
// Returns a reference to the JsonArray or JsonArray::invalid() if the
|
// Returns a reference to the JsonArray or JsonArray::invalid() if the
|
||||||
// variant
|
// variant
|
||||||
@ -55,5 +38,5 @@ class JsonVariantCasts {
|
|||||||
return static_cast<const TImpl *>(this);
|
return static_cast<const TImpl *>(this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
} // namespace Internals
|
||||||
}
|
} // namespace ArduinoJson
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
# MIT License
|
# MIT License
|
||||||
|
|
||||||
add_executable(MiscTests
|
add_executable(MiscTests
|
||||||
deprecated.cpp
|
|
||||||
FloatParts.cpp
|
FloatParts.cpp
|
||||||
std_stream.cpp
|
std_stream.cpp
|
||||||
std_string.cpp
|
std_string.cpp
|
||||||
|
@ -1,140 +0,0 @@
|
|||||||
// ArduinoJson - arduinojson.org
|
|
||||||
// Copyright Benoit Blanchon 2014-2018
|
|
||||||
// MIT License
|
|
||||||
|
|
||||||
#define ARDUINOJSON_ENABLE_DEPRECATED 1
|
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
|
||||||
#include <catch.hpp>
|
|
||||||
|
|
||||||
#if defined(__clang__)
|
|
||||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
|
||||||
#elif defined(__GNUC__)
|
|
||||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
||||||
#elif defined(_MSC_VER)
|
|
||||||
#pragma warning(disable : 4996)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
TEST_CASE("Deprecated functions") {
|
|
||||||
SECTION("JsonVariant::asArray()") {
|
|
||||||
DynamicJsonArray array;
|
|
||||||
JsonVariant variant = array;
|
|
||||||
REQUIRE(variant.asArray().success());
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("JsonVariant::asObject()") {
|
|
||||||
DynamicJsonObject obj;
|
|
||||||
JsonVariant variant = obj;
|
|
||||||
REQUIRE(variant.asObject().success());
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("JsonVariant::asString()") {
|
|
||||||
JsonVariant variant = "hello";
|
|
||||||
REQUIRE(std::string("hello") == variant.asString());
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("JsonArray::removeAt()") {
|
|
||||||
DynamicJsonArray arr;
|
|
||||||
arr.removeAt(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("JsonVariant::JsonVariant(float, uint8_t)") {
|
|
||||||
JsonVariant variant(3.14f, 2);
|
|
||||||
REQUIRE(variant == 3.14f);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("JsonVariant::JsonVariant(double, uint8_t)") {
|
|
||||||
JsonVariant variant(3.14, 2);
|
|
||||||
REQUIRE(variant == 3.14);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("float_with_n_digits()") {
|
|
||||||
JsonVariant variant = float_with_n_digits(3.14f, 4);
|
|
||||||
REQUIRE(variant == 3.14f);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("double_with_n_digits()") {
|
|
||||||
JsonVariant variant = double_with_n_digits(3.14f, 4);
|
|
||||||
REQUIRE(variant == 3.14f);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("JsonArraySubscript::set(double, uint8_t)") {
|
|
||||||
DynamicJsonArray arr;
|
|
||||||
arr.add(666);
|
|
||||||
arr[0].set(123.45, 2);
|
|
||||||
REQUIRE(123.45 == arr[0].as<double>());
|
|
||||||
REQUIRE(true == arr[0].is<double>());
|
|
||||||
REQUIRE(false == arr[0].is<int>());
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("JsonArray::add(double, uint8_t)") {
|
|
||||||
DynamicJsonArray arr;
|
|
||||||
arr.add(3.14159265358979323846, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("JsonArray::add(float, uint8_t)") {
|
|
||||||
DynamicJsonArray arr;
|
|
||||||
arr.add(3.14159265358979323846f, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("JsonObject::set(unsigned char[], double, uint8_t)") {
|
|
||||||
unsigned char key[] = "hello";
|
|
||||||
|
|
||||||
DynamicJsonObject obj;
|
|
||||||
obj.set(key, 3.14, 2);
|
|
||||||
|
|
||||||
REQUIRE(3.14 == obj["hello"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("JsonObject::set(const char*, double, uint8_t)") {
|
|
||||||
DynamicJsonObject obj;
|
|
||||||
obj.set("hello", 123.45, 2);
|
|
||||||
|
|
||||||
REQUIRE(123.45 == obj["hello"].as<double>());
|
|
||||||
REQUIRE(obj["hello"].is<double>());
|
|
||||||
REQUIRE_FALSE(obj["hello"].is<long>());
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("JsonObjectSubscript::set(double, uint8_t)") {
|
|
||||||
DynamicJsonObject obj;
|
|
||||||
obj["hello"].set(123.45, 2);
|
|
||||||
|
|
||||||
REQUIRE(true == obj["hello"].is<double>());
|
|
||||||
REQUIRE(false == obj["hello"].is<long>());
|
|
||||||
REQUIRE(123.45 == obj["hello"].as<double>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_CASE("DynamicJsonBuffer::strdup()") {
|
|
||||||
DynamicJsonBuffer buffer;
|
|
||||||
|
|
||||||
SECTION("char*") {
|
|
||||||
char original[] = "hello";
|
|
||||||
const char* copy = buffer.strdup(original);
|
|
||||||
strcpy(original, "world");
|
|
||||||
REQUIRE(std::string("hello") == copy);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("unsigned char*") {
|
|
||||||
unsigned char value[] = "world";
|
|
||||||
|
|
||||||
DynamicJsonBuffer jsonBuffer;
|
|
||||||
const char* dup = jsonBuffer.strdup(value);
|
|
||||||
|
|
||||||
REQUIRE(static_cast<const void*>(value) != static_cast<const void*>(dup));
|
|
||||||
REQUIRE(std::string("world") == dup);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("std::string") {
|
|
||||||
std::string original("hello");
|
|
||||||
const char* copy = buffer.strdup(original);
|
|
||||||
original[0] = 'w';
|
|
||||||
REQUIRE(std::string("hello") == copy);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("NULL") {
|
|
||||||
const char* original = NULL;
|
|
||||||
const char* copy = buffer.strdup(original);
|
|
||||||
REQUIRE(0 == copy);
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user