Compare commits

..

77 Commits

Author SHA1 Message Date
7abf875071 Set version to 6.19.3 2022-03-08 17:24:14 +01:00
e3e375f5cd MessagePack: serialize round floats as integers (fixes #1718) 2022-02-28 19:38:26 +01:00
ff06292d74 Fix -Wsign-conversion -funsigned-char (fixes #1715) 2022-02-28 10:00:12 +01:00
c1278797f2 CI: use -funsigned-char in one GCC build (issue #1715) 2022-02-28 09:50:32 +01:00
421ecec0dd Tests: trim trailing white spaces 2022-02-25 10:28:42 +01:00
89ed54362b Fix -Wsign-conversion on GCC 8 (fixes #1715) 2022-02-25 10:28:42 +01:00
986f77fa15 Tests: link with -static on MinGW 2022-02-25 10:28:22 +01:00
f831ed395d Fix JsonString operator == and != for non-zero-terminated string 2022-02-17 17:33:16 +01:00
a880614a75 Fix call of overloaded 'String(const char*, int)' is ambiguous 2022-02-17 17:33:16 +01:00
ef8379df1b Set version to 6.19.2 2022-02-14 09:06:06 +01:00
702f8c2e2f Fix cannot convert 'pgm_p' to 'const void*' (fixes #1707) 2022-02-06 11:14:23 +01:00
6806393285 Wandbox: update compiler version 2022-01-14 09:23:12 +01:00
dea8387586 Publish script: don't stop if wandbox fails 2022-01-14 09:22:55 +01:00
6ea2815341 Set version to 6.19.1 2022-01-14 08:49:57 +01:00
3c145f1782 Add assertions to comfort Clang-Tidy 2022-01-13 20:25:49 +01:00
21b2c76524 Fix filter not working in zero-copy mode (fixes #1697) 2022-01-13 20:25:49 +01:00
4f6244eef4 Replace CopiedString and LinkedString with JsonString 2022-01-13 16:15:53 +01:00
973858b835 Remove unused CopiedString in MemoryPool 2022-01-13 16:10:42 +01:00
ee12155617 Fix crash when adding an object member in a too small JsonDocument 2022-01-13 11:52:45 +01:00
4b4c68df5f Changelog: remove empty line 2022-01-13 11:52:45 +01:00
fcae33d574 Publish script: fix change log extraction code 2022-01-08 17:59:07 +01:00
896f50eeb9 Publish script: check that all required commands are available 2022-01-08 16:40:21 +01:00
9693fd2d74 Set version to 6.19.0 2022-01-08 16:21:29 +01:00
37f1c87338 Publish script: check that all changes are committed 2022-01-08 16:21:09 +01:00
4977de38fc Remove .devcontainer/ 2022-01-05 12:08:30 +01:00
9f4750637b Add PlatformIO badge to README 2022-01-05 12:08:18 +01:00
0c65e13aa3 Add LGTM grade badge to README 2022-01-02 10:12:13 +01:00
af18994deb Update copyright notice 2022-01-01 10:01:05 +01:00
8f9599cd19 Format appveyor.yml 2022-01-01 10:01:05 +01:00
78660c6e07 Fix support of long long in catch 2022-01-01 10:01:05 +01:00
4f786db82d CI: build on multiple versions of MinGW 2022-01-01 09:51:05 +01:00
ad7b749dec CI: build with arduino-cli 2021-12-31 14:39:39 +01:00
29ba744d64 Add a polyfill for pgm_read_ptr() (issue #1433) 2021-12-31 14:39:38 +01:00
a2e1021d7d Use pgm_read_dword() instead of pgm_read_float() (issue #1433) 2021-12-31 14:39:38 +01:00
d20c3c65c8 Add a polyfill for pgm_read_dword() (issue #1433) 2021-12-31 14:39:38 +01:00
8f029e6096 Fix Visual Studio command line error D9025
https://stackoverflow.com/a/58711983/1164966
2021-12-31 14:39:38 +01:00
91ed68b4a6 Fix conflicting definition of ARDUINOJSON_DEFINE_STATIC_ARRAY() 2021-12-31 14:39:38 +01:00
67fc2d9897 Assume PROGMEM is available as soon as ARDUINO is defined (#1693) 2021-12-31 11:00:50 +01:00
055304bf01 Ignore Visual Studio's /out/ folder 2021-12-29 10:23:15 +01:00
c2800ace32 Include Arduino.h before stdlib.h to avoid conflict (closes #1693) 2021-12-27 13:16:24 +01:00
ec7ffa20f2 Avoid Arduino.h when all its features are disabled (fixes #1692) 2021-12-27 13:16:24 +01:00
ada1f2a894 Add support for char[][] in copyArray() 2021-12-20 17:51:44 +01:00
184a7c4fbd Add support for arbitrary array rank in copyArray() 2021-12-20 17:51:27 +01:00
84e9447f12 Remove redundant copy constructor of AllocatorOwner 2021-12-19 14:08:19 +01:00
ca073fda46 Remove version 5 from change log 2021-12-16 14:56:28 +01:00
0f529a3587 Renamed undocumented function isUndefined() to isUnbound() 2021-12-16 14:55:26 +01:00
e16767af92 Avoid pool reallocation in BasicJsonDocument's copy assignment 2021-12-16 14:42:54 +01:00
3166356484 Test capacity after calling BasicJsonDocument's copy assignment 2021-12-16 14:28:30 +01:00
abdd9d81db Reorder lines in changelog 2021-12-14 10:42:01 +01:00
3bf47761c8 Fix return type of StaticJsonDocument::operator= 2021-12-14 10:41:25 +01:00
f39d8f548f CI: Add Visual Studio 2022 2021-12-12 15:48:51 +01:00
90d750e4d9 Increase coverage 2021-12-07 16:08:44 +01:00
ca24ed48f5 Separate string adapter from storage policy 2021-12-07 16:08:44 +01:00
51937778dd Add operator<<(std::ostream&, const JsonString&) 2021-12-07 16:08:44 +01:00
be70f6ddd7 Support NUL inside string values (issue #1646) 2021-12-07 16:08:44 +01:00
a27398e445 Check for NUL terminator in MemoryPool::findString() 2021-11-24 19:06:49 +01:00
43b2e2e774 Append terminator in saveStringFromFreeZone() 2021-11-24 19:06:49 +01:00
62f9b94ab1 Add CopiedString and LinkedString 2021-11-24 19:06:49 +01:00
b06bbd9d2a Fix inconsistent pool size in BasicJsonDocument's copy constructor 2021-11-23 10:49:35 +01:00
2df1bc7d4f Fix call of overloaded 'swap(...)' is ambiguous (fixes #1678) 2021-11-23 10:47:31 +01:00
599e927590 Fix JsonVariant::memoryUsage() for raw strings 2021-11-12 16:55:41 +01:00
0429016ff1 Remove IsWriteableString 2021-11-12 15:28:33 +01:00
bd42b9638a README: add sponsors section 2021-11-11 09:45:59 +01:00
b1a826b03a README: remove empty lines between the badges 2021-11-11 09:23:58 +01:00
5ed5f3687b Improve test coverage 2021-10-24 09:58:39 +02:00
943a902a0b Remove DeserializationError == bool and DeserializationError != bool 2021-10-24 09:58:39 +02:00
a7873389c6 Change VariantData::asString() return type to JsonString 2021-10-24 09:58:39 +02:00
acfa174333 Add safe bool idiom in JsonString 2021-10-24 09:58:39 +02:00
8418845c8d Add is<JsonString>() 2021-10-24 09:58:39 +02:00
df4a4b9e1d Add as<JsonString>() 2021-10-24 09:58:13 +02:00
7f5497db55 VSCode: exclude catch/ from search 2021-10-22 14:11:50 +02:00
e4658e963f Change the default of ARDUINOJSON_USE_LONG_LONG to 1 on 32-bit platforms 2021-10-19 22:25:45 +02:00
7764515f56 Change the default of ARDUINOJSON_USE_DOUBLE to 1 2021-10-19 22:25:45 +02:00
7046c38c84 Remove ARDUINOJSON_EMBEDDED_MODE 2021-10-19 22:25:45 +02:00
9e9bb30a57 CI: Test ArduinoJson's configuration 2021-10-19 15:36:32 +02:00
41d1be24cc Update GitHub issue templates 2021-10-11 15:20:14 +02:00
7d3b475e24 Update the README 2021-10-11 15:17:36 +02:00
373 changed files with 2555 additions and 2345 deletions

View File

@ -1,45 +0,0 @@
FROM ubuntu:20.04
RUN apt-get update && \
apt-get install -y software-properties-common curl && \
apt-get upgrade -y
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 15CF4D18AF4F7421
RUN add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ trusty main' && \
add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ trusty universe' && \
add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial main' && \
add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial universe' && \
add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic main' && \
add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic universe' && \
add-apt-repository -yn 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-6.0 main' && \
add-apt-repository -yn 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-7 main' && \
add-apt-repository -yn 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-8 main' && \
add-apt-repository -yn 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main' && \
add-apt-repository -yn 'deb http://mirrors.kernel.org/ubuntu hirsute main universe'
RUN apt-get update && apt-get -y install \
cmake \
ninja-build \
git \
clang-format \
g++-4.4 \
g++-4.6 \
g++-4.7 \
g++-4.8 \
g++-4.9 \
g++-5 \
g++-7 \
g++-8 \
g++-9 \
g++-10 \
g++-11 \
clang-3.5 \
clang-3.6 \
clang-3.7 \
clang-3.8 \
clang-3.9 \
clang-6.0 \
clang-7 \
clang-8 \
clang-9 \
clang-10 \
clang-11

View File

@ -1,24 +0,0 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.183.0/containers/ubuntu
{
"name": "Ubuntu",
"build": {
"dockerfile": "Dockerfile"
},
// Set *default* container specific settings.json values on container create.
"settings": {},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-vscode.cmake-tools",
"ms-vscode.cpptools",
"xaver.clang-format"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "uname -a",
}

View File

@ -1,14 +0,0 @@
<!--
Before opening an issue, please read the FAQ:
https://arduinojson.org/faq/
Please provide all the relevant information:
* good title
* short description of the problem
* target platform
* compiler model and version
* MVCE (https://stackoverflow.com/help/mcve)
* compiler output
Good questions get fast answers!
-->

54
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@ -0,0 +1,54 @@
---
name: 🐛 Bug report
about: Report a bug in ArduinoJson
title: ''
labels: 'bug'
assignees: ''
---
<!-- ⚠️ IMPORTANT ⚠️
Before opening a bug report, please use the ArduinoJson Troubleshooter as it may find a solution to your issue; if not, please include the Troubleshooter's report in the description.
-->
**Describe the bug**
A clear and concise description of what the bug is.
**Troubleshooter report**
Here is the report generated by the [ArduinoJson Troubleshooter](https://arduinojson.org/v6/troubleshooter/):
[Paste the report here]
**Environment**
Here is the environment that I used:
* Microcontroller: [e.g. ESP8266]
* Core/runtime: [e.g. ESP8266 core for Arduino v3.0.2]
* IDE: [e.g. Arduino IDE 1.8.16]
**Reproduction**
Here is a small snippet that reproduces the issue.
```c++
DynamicJsonDocument doc(1024);
DeserializationError error = deserializeJson(doc, "{\"hello\":\"world\"}");
[insert repro code here]
```
**Compiler output**
If relevant, include the complete compiler output (i.e. not just the line that contains the error.)
**Program output**
If relevant, include the repro program output.
Expected output:
```
[insert expected output here]
```
Actual output:
```
[insert actual output here]
```

8
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@ -0,0 +1,8 @@
blank_issues_enabled: true
contact_links:
- name: 👨‍🏫 ArduinoJson Assistant
url: https://arduinojson.org/v6/assistant/
about: An online tool that computes memory requirements and generates scaffolding code for your project.
- name: 👨‍⚕️ ArduinoJson Troubleshooter
url: https://arduinojson.org/v6/troubleshooter/
about: An online tool that helps you diagnose the most common issues with ArduinoJson.

View File

@ -0,0 +1,19 @@
---
name: 💡 Feature request
about: Suggest an idea for ArduinoJson
title: ''
labels: enhancement
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

51
.github/ISSUE_TEMPLATE/help.md vendored Normal file
View File

@ -0,0 +1,51 @@
---
name: 😭 Help!
about: Ask for help
title: ''
labels: 'question'
assignees: ''
---
<!-- ⚠️ IMPORTANT ⚠️
Before asking for help, please use the ArduinoJson Troubleshooter as it may find a solution to your issue; if not, please include the Troubleshooter's report in the description.
-->
**Describe the issue**
A clear and concise description of what you're trying to do.
You don't need to explain every aspect of your project: focus on the problem you're having.
**Troubleshooter report**
Here is the report generated by the [ArduinoJson Troubleshooter](https://arduinojson.org/v6/troubleshooter/):
[Paste the report here]
**Environment**
Here is the environment that I'm using':
* Microconroller: [e.g. ESP8266]
* Core/runtime: [e.g. ESP8266 core for Arduino v3.0.2]
* IDE: [e.g. Arduino IDE 1.8.16]
**Reproduction**
Here is a small snippet that demonstrate the problem.
```c++
DynamicJsonDocument doc(1024);
DeserializationError error = deserializeJson(doc, "{\"hello\":\"world\"}");
// insert code here
```
**Program output**
If relevant, include the program output.
Expected output:
```
[insert expected output here]
```
Actual output:
```
[insert actual output here]
```

View File

@ -40,6 +40,7 @@ jobs:
- gcc: "9"
cxxflags: -fsanitize=address -fno-sanitize-recover=all
- gcc: "10"
cxxflags: -funsigned-char # Issue #1715
- gcc: "11"
steps:
- name: Install
@ -47,10 +48,10 @@ jobs:
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ trusty main'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ trusty universe'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial main'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial universe'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial universe'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic main'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic universe'
sudo add-apt-repository -yn 'deb http://mirrors.kernel.org/ubuntu hirsute main universe'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic universe'
sudo add-apt-repository -yn 'deb http://mirrors.kernel.org/ubuntu hirsute main universe'
sudo apt-get update
sudo apt-get install -y gcc-${{ matrix.gcc }} g++-${{ matrix.gcc }}
- name: Checkout
@ -103,9 +104,9 @@ jobs:
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ trusty main'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ trusty universe'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial main'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial universe'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial universe'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic main'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic universe'
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic universe'
sudo apt-get update
sudo apt-get install -y clang-${{ matrix.clang }}
- name: Checkout
@ -125,6 +126,42 @@ jobs:
env:
UBSAN_OPTIONS: print_stacktrace=1
conf_test:
name: Test configuration on Linux
needs: [gcc, clang]
runs-on: ubuntu-20.04
steps:
- name: Install
run: sudo apt-get install -y g++-multilib
- name: Checkout
uses: actions/checkout@v2
- name: GCC 32-bit
run: g++ -std=c++11 -m32 -Isrc extras/conf_test/x86.cpp
- name: GCC 64-bit
run: g++ -std=c++11 -m64 -Isrc extras/conf_test/x64.cpp
- name: Clang 32-bit
run: clang++ -std=c++11 -m32 -Isrc extras/conf_test/x86.cpp
- name: Clang 64-bit
run: clang++ -std=c++11 -m64 -Isrc extras/conf_test/x64.cpp
conf_test_windows:
name: Test configuration on Windows
runs-on: windows-2019
needs: [gcc, clang]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: 32-bit
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars32.bat"
cl /Isrc extras/conf_test/x86.cpp
shell: cmd
- name: 64-bit
run: |
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
cl /Isrc extras/conf_test/x64.cpp
shell: cmd
xcode:
name: XCode
needs: clang
@ -175,20 +212,40 @@ jobs:
fail-fast: false
matrix:
include:
- arduino: "1.6.7"
os: ubuntu-18.04 # java.lang.Error: Cannot load com.sun.java.swing.plaf.gtk.GTKLookAndFeel
- core: arduino:avr
board: arduino:avr:uno
- arduino: "1.8.2"
- core: arduino:samd
board: arduino:samd:mkr1000
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build
run: extras/ci/arduino.sh ${{ matrix.board }}
env:
BOARD: ${{ matrix.board }}
VERSION: ${{ matrix.arduino }}
- name: Install arduino-cli
run: brew update && brew install arduino-cli
- name: Install core
run: arduino-cli core install ${{ matrix.core }}
- name: Install libraries
run: arduino-cli lib install SD Ethernet
- name: Build JsonConfigFile
run: arduino-cli compile --library . --warnings all -b ${{ matrix.board }} "examples/JsonConfigFile/JsonConfigFile.ino"
- name: Build JsonFilterExample
run: arduino-cli compile --library . --warnings all -b ${{ matrix.board }} "examples/JsonFilterExample/JsonFilterExample.ino"
- name: Build JsonGeneratorExample
run: arduino-cli compile --library . --warnings all -b ${{ matrix.board }} "examples/JsonGeneratorExample/JsonGeneratorExample.ino"
- name: Build JsonHttpClient
run: arduino-cli compile --library . --warnings all -b ${{ matrix.board }} "examples/JsonHttpClient/JsonHttpClient.ino"
- name: Build JsonParserExample
run: arduino-cli compile --library . --warnings all -b ${{ matrix.board }} "examples/JsonParserExample/JsonParserExample.ino"
- name: Build JsonServer
run: arduino-cli compile --library . --warnings all -b ${{ matrix.board }} "examples/JsonServer/JsonServer.ino"
- name: Build JsonUdpBeacon
run: arduino-cli compile --library . --warnings all -b ${{ matrix.board }} "examples/JsonUdpBeacon/JsonUdpBeacon.ino"
- name: Build MsgPackParser
run: arduino-cli compile --library . --warnings all -b ${{ matrix.board }} "examples/MsgPackParser/MsgPackParser.ino"
- name: Build ProgmemExample
run: arduino-cli compile --library . --warnings all -b ${{ matrix.board }} "examples/ProgmemExample/ProgmemExample.ino"
- name: Build StringExample
run: arduino-cli compile --library . --warnings all -b ${{ matrix.board }} "examples/StringExample/StringExample.ino"
platformio:
name: PlatformIO
@ -203,29 +260,36 @@ jobs:
libraries:
- SD
- Ethernet
conf_test: avr
- platform: espressif8266
board: huzzah
conf_test: esp8266
- platform: espressif32
board: esp32dev
libraries:
- Ethernet
conf_test: esp8266
- platform: atmelsam
board: mkr1000USB
libraries:
- SD
- Ethernet
conf_test: esp8266
- platform: teensy
board: teensy31
conf_test: esp8266
- platform: ststm32
board: adafruit_feather_f405
libraries:
- SD
- Ethernet
conf_test: esp8266
- platform: nordicnrf52
board: adafruit_feather_nrf52840
libraries:
- SD
- Ethernet
conf_test: esp8266
steps:
- name: Checkout
uses: actions/checkout@v2
@ -256,6 +320,9 @@ jobs:
- name: Install libraries
if: ${{ matrix.libraries }}
run: platformio lib install arduino-libraries/${{ join(matrix.libraries, ' arduino-libraries/') }}
- name: Test configuration
run: platformio ci "extras/conf_test/${{ matrix.conf_test }}.cpp" -l '.' -b ${{ matrix.board }}
if: ${{ matrix.conf_test }}
- name: Build JsonConfigFile
run: platformio ci "examples/JsonConfigFile/JsonConfigFile.ino" -l '.' -b ${{ matrix.board }}
- name: Build JsonFilterExample

1
.gitignore vendored
View File

@ -10,6 +10,7 @@
/extras/fuzzing/*_fuzzer.options
/extras/fuzzing/*_fuzzer_seed_corpus.zip
.vs/
/out/
# Used by CI for Particle
/src/*.ino

View File

@ -15,5 +15,8 @@
"xlocnum": "cpp",
"xloctime": "cpp",
"xstring": "cpp"
},
"search.exclude": {
"/extras/tests/catch/*": true
}
}

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include "src/ArduinoJson.h"

View File

@ -1,6 +1,48 @@
ArduinoJson: change log
=======================
v6.19.3 (2022-03-08)
-------
* Fix `call of overloaded 'String(const char*, int)' is ambiguous`
* Fix `JsonString` operator `==` and `!=` for non-zero-terminated string
* Fix `-Wsign-conversion` on GCC 8 (issue #1715)
* MessagePack: serialize round floats as integers (issue #1718)
v6.19.2 (2022-02-14)
-------
* Fix `cannot convert 'pgm_p' to 'const void*'` (issue #1707)
v6.19.1 (2022-01-14)
-------
* Fix crash when adding an object member in a too small `JsonDocument`
* Fix filter not working in zero-copy mode (issue #1697)
v6.19.0 (2022-01-08)
-------
* Remove `ARDUINOJSON_EMBEDDED_MODE` and assume we run on an embedded platform.
Dependent settings (like `ARDUINOJSON_DEFAULT_NESTING_LIMIT`) must be set individually.
* Change the default of `ARDUINOJSON_USE_DOUBLE` to `1`
* Change the default of `ARDUINOJSON_USE_LONG_LONG` to `1` on 32-bit platforms
* Add `as<JsonString>()` and `is<JsonString>()`
* Add safe bool idiom in `JsonString`
* Add support for NUL in string values (issue #1646)
* Add support for arbitrary array rank in `copyArray()`
* Add support for `char[][]` in `copyArray()`
* Remove `DeserializationError == bool` and `DeserializationError != bool`
* Renamed undocumented function `isUndefined()` to `isUnbound()`
* Fix `JsonVariant::memoryUsage()` for raw strings
* Fix `call of overloaded 'swap(BasicJsonDocument&, BasicJsonDocument&)' is ambiguous` (issue #1678)
* Fix inconsistent pool capacity between `BasicJsonDocument`'s copy and move constructors
* Fix inconsistent pool capacity between `BasicJsonDocument`'s copy and move assignments
* Fix return type of `StaticJsonDocument::operator=`
* Avoid pool reallocation in `BasicJsonDocument`'s copy assignment if capacity is the same
* Avoid including `Arduino.h` when all its features are disabled (issue #1692, PR #1693 by @paulocsanz)
* Assume `PROGMEM` is available as soon as `ARDUINO` is defined (consequence of #1693)
v6.18.5 (2021-09-28)
-------
@ -731,423 +773,3 @@ v6.0.0-beta (2018-06-07)
> obj["key"] = "value";
> serializeJson(doc, Serial);
> ```
v5.13.2
-------
* Fixed `JsonBuffer::parse()` not respecting nesting limit correctly (issue #693)
* Fixed inconsistencies in nesting level counting (PR #695 from Zhenyu Wu)
* Fixed null values that could be pass to `strcmp()` (PR #745 from Mike Karlesky)
* Added macros `ARDUINOJSON_VERSION`, `ARDUINOJSON_VERSION_MAJOR`...
v5.13.1
-------
* Fixed `JsonVariant::operator|(int)` that returned the default value if the variant contained a double (issue #675)
* Allowed non-quoted key to contain underscores (issue #665)
v5.13.0
-------
* Changed the rules of string duplication (issue #658)
* `RawJson()` accepts any kind of string and obeys to the same rules for duplication
* Changed the return type of `strdup()` to `const char*` to prevent double duplication
* Marked `strdup()` as deprecated
> ### New rules for string duplication
>
> | type | duplication |
> |:---------------------------|:------------|
> | const char* | no |
> | char* | ~~no~~ yes |
> | String | yes |
> | std::string | yes |
> | const __FlashStringHelper* | yes |
>
> These new rules make `JsonBuffer::strdup()` useless.
v5.12.0
-------
* Added `JsonVariant::operator|` to return a default value (see below)
* Added a clear error message when compiled as C instead of C++ (issue #629)
* Added detection of MPLAB XC compiler (issue #629)
* Added detection of Keil ARM Compiler (issue #629)
* Added an example that shows how to save and load a configuration file
* Reworked all other examples
> ### How to use the new feature?
>
> If you have a block like this:
>
> ```c++
> const char* ssid = root["ssid"];
> if (!ssid)
> ssid = "default ssid";
> ```
>
> You can simplify like that:
>
> ```c++
> const char* ssid = root["ssid"] | "default ssid";
> ```
v5.11.2
-------
* Fixed `DynamicJsonBuffer::clear()` not resetting allocation size (issue #561)
* Fixed incorrect rounding for float values (issue #588)
v5.11.1
-------
* Removed dependency on `PGM_P` as Particle 0.6.2 doesn't define it (issue #546)
* Fixed warning "dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]"
* Fixed warning "floating constant exceeds range of 'float' [-Woverflow]" (issue #544)
* Fixed warning "this statement may fall through" [-Wimplicit-fallthrough=] (issue #539)
* Removed `ARDUINOJSON_DOUBLE_IS_64BITS` as it became useless.
* Fixed too many decimals places in float serialization (issue #543)
v5.11.0
-------
* Made `JsonBuffer` non-copyable (PR #524 by @luisrayas3)
* Added `StaticJsonBuffer::clear()`
* Added `DynamicJsonBuffer::clear()`
v5.10.1
-------
* Fixed IntelliSense errors in Visual Micro (issue #483)
* Fixed compilation in IAR Embedded Workbench (issue #515)
* Fixed reading "true" as a float (issue #516)
* Added `ARDUINOJSON_DOUBLE_IS_64BITS`
* Added `ARDUINOJSON_EMBEDDED_MODE`
v5.10.0
-------
* Removed configurable number of decimal places (issues #288, #427 and #506)
* Changed exponentiation thresholds to `1e7` and `1e-5` (issues #288, #427 and #506)
* `JsonVariant::is<double>()` now returns `true` for integers
* Fixed error `IsBaseOf is not a member of ArduinoJson::TypeTraits` (issue #495)
* Fixed error `forming reference to reference` (issue #495)
> ### BREAKING CHANGES :warning:
>
> | Old syntax | New syntax |
> |:--------------------------------|:--------------------|
> | `double_with_n_digits(3.14, 2)` | `3.14` |
> | `float_with_n_digits(3.14, 2)` | `3.14f` |
> | `obj.set("key", 3.14, 2)` | `obj["key"] = 3.14` |
> | `arr.add(3.14, 2)` | `arr.add(3.14)` |
>
> | Input | Old output | New output |
> |:----------|:-----------|:-----------|
> | `3.14159` | `3.14` | `3.14159` |
> | `42.0` | `42.00` | `42` |
> | `0.0` | `0.00` | `0` |
>
> | Expression | Old result | New result |
> |:-------------------------------|:-----------|:-----------|
> | `JsonVariant(42).is<int>()` | `true` | `true` |
> | `JsonVariant(42).is<float>()` | `false` | `true` |
> | `JsonVariant(42).is<double>()` | `false` | `true` |
v5.9.0
------
* Added `JsonArray::remove(iterator)` (issue #479)
* Added `JsonObject::remove(iterator)`
* Renamed `JsonArray::removeAt(size_t)` into `remove(size_t)`
* Renamed folder `include/` to `src/`
* Fixed warnings `floating constant exceeds range of float`and `floating constant truncated to zero` (issue #483)
* Removed `Print` class and converted `printTo()` to a template method (issue #276)
* Removed example `IndentedPrintExample.ino`
* Now compatible with Particle 0.6.1, thanks to Jacob Nite (issue #294 and PR #461 by @foodbag)
v5.8.4
------
* Added custom implementation of `strtod()` (issue #453)
* Added custom implementation of `strtol()` (issue #465)
* `char` is now treated as an integral type (issue #337, #370)
v5.8.3
------
* Fixed an access violation in `DynamicJsonBuffer` when memory allocation fails (issue #433)
* Added operators `==` and `!=` for two `JsonVariant`s (issue #436)
* Fixed `JsonVariant::operator[const FlashStringHelper*]` (issue #441)
v5.8.2
------
* Fixed parsing of comments (issue #421)
* Fixed ignored `Stream` timeout (issue #422)
* Made sure we don't read more that necessary (issue #422)
* Fixed error when the key of a `JsonObject` is a `char[]` (issue #423)
* Reduced code size when using `const` references
* Fixed error with string of type `unsigned char*` (issue #428)
* Added `deprecated` attribute on `asArray()`, `asObject()` and `asString()` (issue #420)
v5.8.1
------
* Fixed error when assigning a `volatile int` to a `JsonVariant` (issue #415)
* Fixed errors with Variable Length Arrays (issue #416)
* Fixed error when both `ARDUINOJSON_ENABLE_STD_STREAM` and `ARDUINOJSON_ENABLE_ARDUINO_STREAM` are set to `1`
* Fixed error "Stream does not name a type" (issue #412)
v5.8.0
------
* Added operator `==` to compare `JsonVariant` and strings (issue #402)
* Added support for `Stream` (issue #300)
* Reduced memory consumption by not duplicating spaces and comments
> ### BREAKING CHANGES :warning:
>
> `JsonBuffer::parseObject()` and `JsonBuffer::parseArray()` have been pulled down to the derived classes `DynamicJsonBuffer` and `StaticJsonBufferBase`.
>
> This means that if you have code like:
>
> ```c++
> void myFunction(JsonBuffer& jsonBuffer);
> ```
>
> you need to replace it with one of the following:
>
> ```c++
> void myFunction(DynamicJsonBuffer& jsonBuffer);
> void myFunction(StaticJsonBufferBase& jsonBuffer);
> template<typename TJsonBuffer> void myFunction(TJsonBuffer& jsonBuffer);
> ```
v5.7.3
------
* Added an `printTo(char[N])` and `prettyPrintTo(char[N])` (issue #292)
* Added ability to set a nested value like this: `root["A"]["B"] = "C"` (issue #352)
* Renamed `*.ipp` to `*Impl.hpp` because they were ignored by Arduino IDE (issue #396)
v5.7.2
------
* Made PROGMEM available on more platforms (issue #381)
* Fixed PROGMEM causing an exception on ESP8266 (issue #383)
v5.7.1
------
* Added support for PROGMEM (issue #76)
* Fixed compilation error when index is not an `int` (issue #381)
v5.7.0
------
* Templatized all functions using `String` or `std::string`
* Removed `ArduinoJson::String`
* Removed `JsonVariant::defaultValue<T>()`
* Removed non-template `JsonObject::get()` and `JsonArray.get()`
* Fixed support for `StringSumHelper` (issue #184)
* Replaced `ARDUINOJSON_USE_ARDUINO_STRING` by `ARDUINOJSON_ENABLE_STD_STRING` and `ARDUINOJSON_ENABLE_ARDUINO_STRING` (issue #378)
* Added example `StringExample.ino` to show where `String` can be used
* Increased default nesting limit to 50 when compiled for a computer (issue #349)
> ### BREAKING CHANGES :warning:
>
> The non-template functions `JsonObject::get()` and `JsonArray.get()` have been removed. This means that you need to explicitely tell the type you expect in return.
>
> Old code:
>
> ```c++
> #define ARDUINOJSON_USE_ARDUINO_STRING 0
> JsonVariant value1 = myObject.get("myKey");
> JsonVariant value2 = myArray.get(0);
> ```
>
> New code:
>
> ```c++
> #define ARDUINOJSON_ENABLE_ARDUINO_STRING 0
> #define ARDUINOJSON_ENABLE_STD_STRING 1
> JsonVariant value1 = myObject.get<JsonVariant>("myKey");
> JsonVariant value2 = myArray.get<JsonVariant>(0);
> ```
v5.6.7
------
* Fixed `array[idx].as<JsonVariant>()` and `object[key].as<JsonVariant>()`
* Fixed return value of `JsonObject::set()` (issue #350)
* Fixed undefined behavior in `Prettyfier` and `Print` (issue #354)
* Fixed parser that incorrectly rejected floats containing a `+` (issue #349)
v5.6.6
------
* Fixed `-Wparentheses` warning introduced in v5.6.5 (PR #335 by @nuket)
* Added `.mbedignore` for ARM mbdeb (PR #334 by @nuket)
* Fixed `JsonVariant::success()` which didn't propagate `JsonArray::success()` nor `JsonObject::success()` (issue #342).
v5.6.5
------
* `as<char*>()` now returns `true` when input is `null` (issue #330)
v5.6.4
------
* Fixed error in float serialization (issue #324)
v5.6.3
------
* Improved speed of float serialization (about twice faster)
* Added `as<JsonArray>()` as a synonym for `as<JsonArray&>()`... (issue #291)
* Fixed `call of overloaded isinf(double&) is ambiguous` (issue #284)
v5.6.2
------
* Fixed build when another lib does `#undef isnan` (issue #284)
v5.6.1
------
* Added missing `#pragma once` (issue #310)
v5.6.0
------
* ArduinoJson is now a header-only library (issue #199)
v5.5.1
------
* Fixed compilation error with Intel Galileo (issue #299)
v5.5.0
------
* Added `JsonVariant::success()` (issue #279)
* Renamed `JsonVariant::invalid<T>()` to `JsonVariant::defaultValue<T>()`
v5.4.0
------
* Changed `::String` to `ArduinoJson::String` (issue #275)
* Changed `::Print` to `ArduinoJson::Print` too
v5.3.0
------
* Added custom implementation of `ftoa` (issues #266, #267, #269 and #270)
* Added `JsonVariant JsonBuffer::parse()` (issue #265)
* Fixed `unsigned long` printed as `signed long` (issue #170)
v5.2.0
------
* Added `JsonVariant::as<char*>()` as a synonym for `JsonVariant::as<const char*>()` (issue #257)
* Added example `JsonHttpClient` (issue #256)
* Added `JsonArray::copyTo()` and `JsonArray::copyFrom()` (issue #254)
* Added `RawJson()` to insert pregenerated JSON portions (issue #259)
v5.1.1
------
* Removed `String` duplication when one replaces a value in a `JsonObject` (PR #232 by @ulion)
v5.1.0
------
* Added support of `long long` (issue #171)
* Moved all build settings to `ArduinoJson/Configuration.hpp`
> ### BREAKING CHANGE :warning:
>
> If you defined `ARDUINOJSON_ENABLE_STD_STREAM`, you now need to define it to `1`.
v5.0.8
------
* Made the library compatible with [PlatformIO](http://platformio.org/) (issue #181)
* Fixed `JsonVariant::is<bool>()` that was incorrectly returning false (issue #214)
v5.0.7
------
* Made library easier to use from a CMake project: simply `add_subdirectory(ArduinoJson/src)`
* Changed `String` to be a `typedef` of `std::string` (issues #142 and #161)
> ### BREAKING CHANGES :warning:
>
> - `JsonVariant(true).as<String>()` now returns `"true"` instead of `"1"`
> - `JsonVariant(false).as<String>()` now returns `"false"` instead of `"0"`
v5.0.6
------
* Added parameter to `DynamicJsonBuffer` constructor to set initial size (issue #152)
* Fixed warning about library category in Arduino 1.6.6 (issue #147)
* Examples: Added a loop to wait for serial port to be ready (issue #156)
v5.0.5
------
* Added overload `JsonObjectSuscript::set(value, decimals)` (issue #143)
* Use `float` instead of `double` to reduce the size of `JsonVariant` (issue #134)
v5.0.4
------
* Fixed ambiguous overload with `JsonArraySubscript` and `JsonObjectSubscript` (issue #122)
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
------
* Fixed segmentation fault in `parseObject(String)` and `parseArray(String)`, when the
`StaticJsonBuffer` is too small to hold a copy of the string
* Fixed Clang warning "register specifier is deprecated" (issue #102)
* Fixed GCC warning "declaration shadows a member" (issue #103)
* Fixed memory alignment, which made ESP8266 crash (issue #104)
* Fixed compilation on Visual Studio 2010 and 2012 (issue #107)
v5.0.1
------
* Fixed compilation with Arduino 1.0.6 (issue #99)
v5.0.0
------
* Added support of `String` class (issues #55, #56, #70, #77)
* Added `JsonBuffer::strdup()` to make a copy of a string (issues #10, #57)
* Implicitly call `strdup()` for `String` but not for `char*` (issues #84, #87)
* Added support of non standard JSON input (issue #44)
* Added support of comments in JSON input (issue #88)
* Added implicit cast between numerical types (issues #64, #69, #93)
* Added ability to read number values as string (issue #90)
* Redesigned `JsonVariant` to leverage converting constructors instead of assignment operators (issue #66)
* Switched to new the library layout (requires Arduino 1.0.6 or above)
> ### BREAKING CHANGES :warning:
>
> - `JsonObject::add()` was renamed to `set()`
> - `JsonArray::at()` and `JsonObject::at()` were renamed to `get()`
> - Number of digits of floating point value are now set with `double_with_n_digits()`
**Personal note about the `String` class**:
Support of the `String` class has been added to the library because many people use it in their programs.
However, you should not see this as an invitation to use the `String` class.
The `String` class is **bad** because it uses dynamic memory allocation.
Compared to static allocation, it compiles to a bigger, slower program, and is less predictable.
You certainly don't want that in an embedded environment!

View File

@ -1,17 +1,16 @@
# ArduinoJson - https://arduinojson.org
# Copyright Benoit Blanchon 2014-2021
# Copyright © 2014-2022, Benoit BLANCHON
# MIT License
cmake_minimum_required(VERSION 3.3)
cmake_minimum_required(VERSION 3.15)
if(ESP_PLATFORM)
# Build ArduinoJson as an ESP-IDF component
idf_component_register(INCLUDE_DIRS src)
target_compile_definitions(${COMPONENT_LIB} INTERFACE ARDUINOJSON_EMBEDDED_MODE=1)
return()
endif()
project(ArduinoJson VERSION 6.18.5)
project(ArduinoJson VERSION 6.19.3)
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
include(CTest)

View File

@ -1,7 +1,7 @@
The MIT License (MIT)
---------------------
Copyright © 2014-2021 Benoit BLANCHON
Copyright © 2014-2022, Benoit BLANCHON
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@ -5,15 +5,13 @@
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/bblanchon/ArduinoJson/Continuous%20Integration?logo=github)](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A6.x)
[![Continuous Integration](https://ci.appveyor.com/api/projects/status/m7s53wav1l0abssg/branch/6.x?svg=true)](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
[![Fuzzing Status](https://oss-fuzz-build-logs.storage.googleapis.com/badges/arduinojson.svg)](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
[![Coverage Status](https://coveralls.io/repos/github/bblanchon/ArduinoJson/badge.svg?branch=6.x)](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
[![Discord](https://img.shields.io/discord/844900310409150494.svg?logo=discord&logoColor=white&color=007ec6)](https://discord.gg/DzN6hHHD4h)
[![LGTM Grade](https://img.shields.io/lgtm/grade/cpp/github/bblanchon/ArduinoJson?label=quality&logo=lgtm)](https://lgtm.com/projects/g/bblanchon/ArduinoJson/)
[![Coveralls branch](https://img.shields.io/coveralls/github/bblanchon/ArduinoJson/6.x?logo=coveralls)](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
[![Arduino Library Manager](https://img.shields.io/static/v1?label=Arduino&message=v6.19.3&logo=arduino&logoColor=white&color=blue)](https://www.ardu-badge.com/ArduinoJson/6.19.3)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/bblanchon/library/ArduinoJson.svg?version=6.19.3)](https://registry.platformio.org/packages/libraries/bblanchon/ArduinoJson?version=6.19.3)
[![GitHub stars](https://img.shields.io/github/stars/bblanchon/ArduinoJson?style=flat&logo=github)](https://github.com/bblanchon/ArduinoJson/stargazers)
[![GitHub Sponsors](https://img.shields.io/github/sponsors/bblanchon?logo=github)](https://github.com/sponsors/bblanchon)
[![arduino-library-badge](https://www.ardu-badge.com/badge/ArduinoJson.svg?version=6.18.5)](https://www.ardu-badge.com/ArduinoJson/6.18.5)
ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
## Features
@ -36,10 +34,10 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
* [Consumes roughly 10% less RAM than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/?utm_source=github&utm_medium=readme)
* [Fixed memory allocation, no heap fragmentation](https://arduinojson.org/v6/api/jsondocument/?utm_source=github&utm_medium=readme)
* [Optionally works without heap memory (zero malloc)](https://arduinojson.org/v6/api/staticjsondocument/?utm_source=github&utm_medium=readme)
* Deduplicates strings
* [Deduplicates strings](https://arduinojson.org/news/2020/08/01/version-6-16-0/?utm_source=github&utm_medium=readme)
* Versatile
* Supports [custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/?utm_source=github&utm_medium=readme)
* Supports [`String`](https://arduinojson.org/v6/api/config/enable_arduino_string/?utm_source=github&utm_medium=readme), [`std::string`](https://arduinojson.org/v6/api/config/enable_std_string/?utm_source=github&utm_medium=readme) and [`std::string_view`](https://arduinojson.org/v6/api/config/enable_string_view/?utm_source=github&utm_medium=readme)
* Supports [`String`](https://arduinojson.org/v6/api/config/enable_arduino_string/?utm_source=github&utm_medium=readme), [`std::string`](https://arduinojson.org/v6/api/config/enable_std_string/?utm_source=github&utm_medium=readme), and [`std::string_view`](https://arduinojson.org/v6/api/config/enable_string_view/?utm_source=github&utm_medium=readme)
* Supports [`Stream`](https://arduinojson.org/v6/api/config/enable_arduino_stream/?utm_source=github&utm_medium=readme) and [`std::istream`/`std::ostream`](https://arduinojson.org/v6/api/config/enable_std_stream/?utm_source=github&utm_medium=readme)
* Supports [Flash strings](https://arduinojson.org/v6/api/config/enable_progmem/?utm_source=github&utm_medium=readme)
* Supports [custom readers](https://arduinojson.org/v6/api/json/deserializejson/?utm_source=github&utm_medium=readme#custom-reader) and [custom writers](https://arduinojson.org/v6/api/json/serializejson/?utm_source=github&utm_medium=readme#custom-writer)
@ -53,9 +51,10 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
* Arduino boards: [Uno](https://amzn.to/38aL2ik), [Due](https://amzn.to/36YkWi2), [Micro](https://amzn.to/35WkdwG), [Nano](https://amzn.to/2QTvwRX), [Mega](https://amzn.to/36XWhuf), [Yun](https://amzn.to/30odURc), [Leonardo](https://amzn.to/36XWjlR)...
* Espressif chips: [ESP8266](https://amzn.to/36YluV8), [ESP32](https://amzn.to/2G4pRCB)
* Lolin (WeMos) boards: [D1 mini](https://amzn.to/2QUpz7q), [D1 Mini Pro](https://amzn.to/36UsGSs)...
* Teensy boards: [4.0](https://amzn.to/30ljXGq), [3.2](https://amzn.to/2FT0EuC), [2.0](https://amzn.to/2QXUMXj)
* Teensy boards: [4.0](https://amzn.to/30ljXGq), [3.2](https://amzn.to/2FT0EuC), [2.0](https://amzn.to/2QXUMXj)
* Particle boards: [Argon](https://amzn.to/2FQHa9X), [Boron](https://amzn.to/36WgLUd), [Electron](https://amzn.to/30vEc4k), [Photon](https://amzn.to/387F9Cd)...
* Texas Instruments boards: [MSP430](https://amzn.to/30nJWgg)...
* Soft cores: [Nios II](https://en.wikipedia.org/wiki/Nios_II)...
* Tested on all major development environments
* [Arduino IDE](https://www.arduino.cc/en/Main/Software)
* [Atmel Studio](http://www.atmel.com/microsite/atmel-studio/)
@ -82,7 +81,7 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
* Well tested
* [Unit test coverage close to 100%](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
* Continuously tested on
* [Visual Studio 2010, 2012, 2013, 2015, 2017, 2019](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
* [Visual Studio 2010, 2012, 2013, 2015, 2017, 2019, 2022](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
* [GCC 4.4, 4.6, 4.7, 4.8, 4.9, 5, 6, 7, 8, 9, 10, 11](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
* [Clang 3.5, 3.6, 3.7, 3.8, 3.9, 4.0, 5.0, 6.0, 7, 8, 9, 10](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
* [Continuously fuzzed with Google OSS Fuzz](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
@ -99,6 +98,7 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
* Most popular of all Arduino libraries on [GitHub](https://github.com/search?o=desc&q=arduino+library&s=stars&type=Repositories)
* [Used in hundreds of projects](https://www.hackster.io/search?i=projects&q=arduinojson)
* [Responsive support](https://github.com/bblanchon/ArduinoJson/issues?q=is%3Aissue+is%3Aclosed)
* [Discord server](https://discord.gg/DzN6hHHD4h)
## Quickstart
@ -139,11 +139,24 @@ serializeJson(doc, Serial);
See the [tutorial on arduinojson.org](https://arduinojson.org/doc/encoding/?utm_source=github&utm_medium=readme)
## Support the project ❤️
## Sponsors
Do you like this library?
Please [star this project on GitHub](https://github.com/bblanchon/ArduinoJson/stargazers)!
ArduinoJson is thankful to its sponsors. Please give them a visit; they deserve it!
What? You don't like it but you *love* it?
You can support the project by [purchasing my book](https://arduinojson.org/book/?utm_source=github&utm_medium=readme).
Alternatively, you can make a recurring donation via [GitHub Sponsors](https://github.com/sponsors/bblanchon).
<p>
<a href="https://techexplorations.com/" rel="sponsored">
<img alt="Tech Explorations" src="https://arduinojson.org/images/2021/10/techexplorations.png" width="200">
</a>
<a href="https://www.programmingelectronics.com/" rel="sponsored">
<img src="https://arduinojson.org/images/2021/10/programmingeleactronicsacademy.png" alt="Programming Electronics Academy" width="200">
</a>
</p>
<p>
<a href="https://github.com/1technophile" rel="sponsored">
<img alt="1technophile" src="https://avatars.githubusercontent.com/u/12672732?s=40&v=4">
</a>
</p>
If you run a commercial project that embeds ArduinoJson, think about [sponsoring the library's development](https://github.com/sponsors/bblanchon): it ensures the code that your products rely on stays actively maintained. It can also give your project some exposure to the makers' community.
If you are an individual user and want to support the development (or give a sign of appreciation), consider purchasing the book [Mastering ArduinoJson](https://arduinojson.org/book/)&nbsp;❤, or simply [cast a star](https://github.com/bblanchon/ArduinoJson/stargazers)&nbsp;⭐.

View File

@ -1,22 +1,37 @@
version: 6.18.5.{build}
version: 6.19.3.{build}
environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
CMAKE_GENERATOR: Visual Studio 16 2019
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_GENERATOR: Visual Studio 15 2017
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
CMAKE_GENERATOR: Visual Studio 14 2015
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
CMAKE_GENERATOR: Visual Studio 12 2013
- CMAKE_GENERATOR: Visual Studio 11 2012
- CMAKE_GENERATOR: Visual Studio 10 2010
- CMAKE_GENERATOR: MinGW Makefiles
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
CMAKE_GENERATOR: Visual Studio 17 2022
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
CMAKE_GENERATOR: Visual Studio 16 2019
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_GENERATOR: Visual Studio 15 2017
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
CMAKE_GENERATOR: Visual Studio 14 2015
- CMAKE_GENERATOR: Visual Studio 12 2013
- CMAKE_GENERATOR: Visual Studio 11 2012
- CMAKE_GENERATOR: Visual Studio 10 2010
- CMAKE_GENERATOR: Ninja
MINGW: MinGW # MinGW 32-bit 5.3.0
- CMAKE_GENERATOR: Ninja
MINGW32: i686-5.3.0-posix-dwarf-rt_v4-rev0 # MinGW-w64 5.3.0
- CMAKE_GENERATOR: Ninja
MINGW32: i686-6.3.0-posix-dwarf-rt_v5-rev1 # MinGW-w64 6.3.0 i686
- CMAKE_GENERATOR: Ninja
MINGW64: x86_64-6.3.0-posix-seh-rt_v5-rev1 # MinGW-w64 6.3.0 x86_64
- CMAKE_GENERATOR: Ninja
MINGW64: x86_64-7.3.0-posix-seh-rt_v5-rev0 # MinGW-w64 7.3.0 x86_64
- CMAKE_GENERATOR: Ninja
MINGW64: x86_64-8.1.0-posix-seh-rt_v6-rev0 # MinGW-w64 8.1.0 x86_64
configuration: Debug
before_build:
- set PATH=C:\MinGW\bin;%PATH:C:\Program Files\Git\usr\bin;=% # Workaround for CMake not wanting sh.exe on PATH for MinGW
- cmake -DCMAKE_BUILD_TYPE=%CONFIGURATION% -G "%CMAKE_GENERATOR%" .
- set PATH=%PATH:C:\Program Files\Git\usr\bin;=% # Workaround for CMake not wanting sh.exe on PATH for MinGW
- if defined MINGW set PATH=C:\%MINGW%\bin;%PATH%
- if defined MINGW32 set PATH=C:\mingw-w64\%MINGW32%\mingw32\bin;%PATH%
- if defined MINGW64 set PATH=C:\mingw-w64\%MINGW64%\mingw64\bin;%PATH%
- cmake -DCMAKE_BUILD_TYPE=%CONFIGURATION% -G "%CMAKE_GENERATOR%" .
build_script:
- cmake --build . --config %CONFIGURATION%
- cmake --build . --config %CONFIGURATION%
test_script:
- ctest -C %CONFIGURATION% --output-on-failure .
- ctest -C %CONFIGURATION% --output-on-failure .

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
//
// This example shows how to store your project configuration in a file.

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
//
// This example shows how to use DeserializationOpion::Filter

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
//
// This example shows how to generate a JSON document with ArduinoJson.

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
//
// This example shows how to parse a JSON document in an HTTP response.

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
//
// This example shows how to deserialize a JSON document with ArduinoJson.

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
//
// This example shows how to implement an HTTP server that sends a JSON document

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
//
// This example shows how to send a JSON document to a UDP socket.

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
//
// This example shows how to deserialize a MessagePack document with

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
//
// This example shows the different ways you can use Flash strings with
@ -14,8 +14,6 @@
#include <ArduinoJson.h>
void setup() {
#ifdef PROGMEM // <- check that Flash strings are supported
DynamicJsonDocument doc(1024);
// You can use a Flash String as your JSON input.
@ -46,12 +44,6 @@ void setup() {
if (obj["sensor"] == F("gps")) {
// ...
}
#else
#warning PROGMEM is not supported on this platform
#endif
}
void loop() {

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
//
// This example shows the different ways you can use String with ArduinoJson.

View File

@ -18,6 +18,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
-Wparentheses
-Wredundant-decls
-Wshadow
-Wsign-conversion
-Wsign-promo
-Wstrict-aliasing
-Wundef
@ -92,3 +93,9 @@ if(MSVC)
)
endif()
endif()
if(MINGW)
# Static link on MinGW to avoid linking with the wrong DLLs when multiple
# versions are installed.
add_link_options(-static)
endif()

View File

@ -1,20 +0,0 @@
#!/bin/bash -eux
/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16
sleep 3
export DISPLAY=:1.0
mkdir -p /tmp/arduino
curl -sS http://downloads.arduino.cc/arduino-$VERSION-linux64.tar.xz | tar xJ -C /tmp/arduino --strip 1 ||
curl -sS http://downloads.arduino.cc/arduino-$VERSION-linux64.tgz | tar xz -C /tmp/arduino --strip 1
export PATH=$PATH:/tmp/arduino/
if [[ "$BOARD" =~ "arduino:samd:" ]]; then
arduino --install-boards arduino:samd
fi
ln -s $PWD /tmp/arduino/libraries/ArduinoJson
for EXAMPLE in $PWD/examples/*/*.ino; do
arduino --verify --board $BOARD $EXAMPLE
done

View File

@ -1,5 +1,5 @@
# ArduinoJson - https://arduinojson.org
# Copyright Benoit Blanchon 2014-2021
# Copyright © 2014-2022, Benoit BLANCHON
# MIT License
cmake_minimum_required(VERSION 3.5)

View File

@ -1,5 +1,5 @@
# ArduinoJson - https://arduinojson.org
# Copyright Benoit Blanchon 2014-2021
# Copyright © 2014-2022, Benoit BLANCHON
# MIT License
idf_component_register(SRCS "main.cpp"

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

16
extras/conf_test/avr.cpp Normal file
View File

@ -0,0 +1,16 @@
#include <ArduinoJson.h>
static_assert(ARDUINOJSON_USE_LONG_LONG == 0, "ARDUINOJSON_USE_LONG_LONG");
static_assert(ARDUINOJSON_SLOT_OFFSET_SIZE == 1,
"ARDUINOJSON_SLOT_OFFSET_SIZE");
static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
static_assert(sizeof(ARDUINOJSON_NAMESPACE::VariantSlot) == 8,
"sizeof(VariantSlot)");
void setup() {}
void loop() {}

View File

@ -0,0 +1,16 @@
#include <ArduinoJson.h>
static_assert(ARDUINOJSON_USE_LONG_LONG == 1, "ARDUINOJSON_USE_LONG_LONG");
static_assert(ARDUINOJSON_SLOT_OFFSET_SIZE == 2,
"ARDUINOJSON_SLOT_OFFSET_SIZE");
static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
static_assert(sizeof(ARDUINOJSON_NAMESPACE::VariantSlot) == 16,
"sizeof(VariantSlot)");
void setup() {}
void loop() {}

15
extras/conf_test/x64.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <ArduinoJson.h>
static_assert(ARDUINOJSON_USE_LONG_LONG == 1, "ARDUINOJSON_USE_LONG_LONG");
static_assert(ARDUINOJSON_SLOT_OFFSET_SIZE == 4,
"ARDUINOJSON_SLOT_OFFSET_SIZE");
static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
static_assert(sizeof(ARDUINOJSON_NAMESPACE::VariantSlot) == 32,
"sizeof(VariantSlot)");
int main() {}

15
extras/conf_test/x86.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <ArduinoJson.h>
static_assert(ARDUINOJSON_USE_LONG_LONG == 1, "ARDUINOJSON_USE_LONG_LONG");
static_assert(ARDUINOJSON_SLOT_OFFSET_SIZE == 2,
"ARDUINOJSON_SLOT_OFFSET_SIZE");
static_assert(ARDUINOJSON_LITTLE_ENDIAN == 1, "ARDUINOJSON_LITTLE_ENDIAN");
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
static_assert(sizeof(ARDUINOJSON_NAMESPACE::VariantSlot) == 16,
"sizeof(VariantSlot)");
int main() {}

View File

@ -1,5 +1,5 @@
# ArduinoJson - https://arduinojson.org
# Copyright Benoit Blanchon 2014-2021
# Copyright © 2014-2022, Benoit BLANCHON
# MIT License
if(MSVC)

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
// This file is NOT use by Google's OSS fuzz

View File

@ -8,7 +8,7 @@ CHANGELOG="$2"
cat << END
## Changes
$(awk '/\* /{ FOUND=1; print; next } { if (FOUND) exit}' "$CHANGELOG")
$(awk '/\* /{ FOUND=1 } /^[[:space:]]*$/ { if(FOUND) exit } { if(FOUND) print }' "$CHANGELOG")
[View version history](https://github.com/bblanchon/ArduinoJson/blob/$TAG/CHANGELOG.md)
END

View File

@ -2,18 +2,25 @@
set -eu
which awk sed jq 7z curl perl >/dev/null
cd "$(dirname "$0")/../.."
if ! git diff --quiet --exit-code; then
echo "Repository contains uncommitted changes"
exit
fi
VERSION="$1"
DATE=$(date +%F)
TAG="v$VERSION"
VERSION_REGEX="[0-9a-z\\.\\-]+"
VERSION_REGEX='[0-9]+\.[0-9]+\.[0-9]+(-[a-z0-9]+)?'
update_version_in_source () {
IFS=".-" read MAJOR MINOR REVISION EXTRA < <(echo "$VERSION")
UNDERLINE=$(printf -- '-%.0s' $(seq 1 ${#TAG}))
sed -i~ -bE "s/version=$VERSION_REGEX/version=$VERSION/; s|ardu-badge.com/ArduinoJson/$VERSION_REGEX|ardu-badge.com/ArduinoJson/$VERSION|; " README.md
sed -i~ -bE "1,20{s/$VERSION_REGEX/$VERSION/g}" README.md
rm README.md~
sed -i~ -bE "4s/HEAD/$TAG ($DATE)/; 5s/-+/$UNDERLINE/" CHANGELOG.md
@ -62,7 +69,7 @@ push
extras/scripts/build-arduino-package.sh . "../ArduinoJson-$TAG.zip"
extras/scripts/build-single-header.sh "src/ArduinoJson.h" "../ArduinoJson-$TAG.h"
extras/scripts/build-single-header.sh "src/ArduinoJson.hpp" "../ArduinoJson-$TAG.hpp"
extras/scripts/wandbox/publish.sh "../ArduinoJson-$TAG.h" > "../ArduinoJson-$TAG-wandbox.txt"
extras/scripts/wandbox/publish.sh "../ArduinoJson-$TAG.h" > "../ArduinoJson-$TAG-wandbox.txt" || echo "Wandbox failed!"
extras/scripts/get-release-page.sh "$VERSION" "CHANGELOG.md" "../ArduinoJson-$TAG-wandbox.txt" > "../ArduinoJson-$TAG.md"
echo "You can now copy ../ArduinoJson-$TAG.md into arduinojson.org/collections/_versions/$VERSION.md"

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
//
// This example shows how to generate a JSON document with ArduinoJson.

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
//
// This example shows how to deserialize a JSON document with ArduinoJson.

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
//
// This example shows how to generate a JSON document with ArduinoJson.

View File

@ -15,13 +15,13 @@ compile() {
"code":$(read_string "$FILE_PATH"),
"codes": [{"file":"ArduinoJson.h","code":$(read_string "$ARDUINOJSON_H")}],
"options": "warning",
"compiler": "gcc-4.9.3",
"compiler": "gcc-4.9.4",
"save": true
}
END
URL=$(curl -sS -H "Content-type: application/json" -d @parameters.json https://wandbox.org/api/compile.json | jq --raw-output .url)
rm parameters.json
echo "$1: $URL"
[ -n "$URL" ] && echo "$1: $URL"
}
compile "JsonGeneratorExample"

View File

@ -1,5 +1,5 @@
# ArduinoJson - https://arduinojson.org
# Copyright Benoit Blanchon 2014-2021
# Copyright © 2014-2022, Benoit BLANCHON
# MIT License
set(CMAKE_CXX_STANDARD 98)

View File

@ -1,5 +1,5 @@
# ArduinoJson - https://arduinojson.org
# Copyright Benoit Blanchon 2014-2021
# Copyright © 2014-2022, Benoit BLANCHON
# MIT License
if("cxx_nullptr" IN_LIST CMAKE_CXX_COMPILE_FEATURES)

View File

@ -1,5 +1,5 @@
# ArduinoJson - https://arduinojson.org
# Copyright Benoit Blanchon 2014-2021
# Copyright © 2014-2022, Benoit BLANCHON
# MIT License
if(MSVC_VERSION LESS 1910)

View File

@ -8,7 +8,7 @@
#endif
TEST_CASE("string_view") {
StaticJsonDocument<128> doc;
StaticJsonDocument<256> doc;
JsonVariant variant = doc.to<JsonVariant>();
SECTION("deserializeJson()") {
@ -57,6 +57,12 @@ TEST_CASE("string_view") {
doc.add(std::string_view("example two", 7));
REQUIRE(doc.memoryUsage() == JSON_ARRAY_SIZE(2) + 8);
doc.add(std::string_view("example\0tree", 12));
REQUIRE(doc.memoryUsage() == JSON_ARRAY_SIZE(3) + 21);
doc.add(std::string_view("example\0tree and a half", 12));
REQUIRE(doc.memoryUsage() == JSON_ARRAY_SIZE(4) + 21);
}
SECTION("as<std::string_view>()") {
@ -72,6 +78,12 @@ TEST_CASE("string_view") {
REQUIRE(doc["s"].is<std::string_view>() == true);
REQUIRE(doc["i"].is<std::string_view>() == false);
}
SECTION("String containing NUL") {
doc.set(std::string("hello\0world", 11));
REQUIRE(doc.as<std::string_view>().size() == 11);
REQUIRE(doc.as<std::string_view>() == std::string_view("hello\0world", 11));
}
}
using ARDUINOJSON_NAMESPACE::adaptString;
@ -80,10 +92,9 @@ TEST_CASE("StringViewAdapter") {
std::string_view str("bravoXXX", 5);
auto adapter = adaptString(str);
CHECK(adapter.compare(NULL) > 0);
CHECK(adapter.compare("alpha") > 0);
CHECK(adapter.compare("bravo") == 0);
CHECK(adapter.compare("charlie") < 0);
CHECK(stringCompare(adapter, adaptString("alpha", 5)) > 0);
CHECK(stringCompare(adapter, adaptString("bravo", 5)) == 0);
CHECK(stringCompare(adapter, adaptString("charlie", 7)) < 0);
CHECK(adapter.size() == 5);
}

View File

@ -1,5 +1,5 @@
# ArduinoJson - https://arduinojson.org
# Copyright Benoit Blanchon 2014-2021
# Copyright © 2014-2022, Benoit BLANCHON
# MIT License
if(MSVC_VERSION LESS 1910)

View File

@ -1,5 +1,5 @@
# ArduinoJson - https://arduinojson.org
# Copyright Benoit Blanchon 2014-2021
# Copyright © 2014-2022, Benoit BLANCHON
# MIT License
macro(build_should_fail target)

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#define ARDUINOJSON_USE_LONG_LONG 0

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#define ARDUINOJSON_USE_LONG_LONG 0

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
@ -7,3 +7,6 @@
#include "api/Print.h"
#include "api/Stream.h"
#include "api/String.h"
#include "progmem_emulation.hpp"
#define ARDUINO_H_INCLUDED 1

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#pragma once
@ -32,6 +32,17 @@ class String {
return _str == s;
}
String& operator=(const char* s) {
_str.assign(s);
return *this;
}
char operator[](unsigned int index) const {
if (index >= _str.size())
return 0;
return _str[index];
}
friend std::ostream& operator<<(std::ostream& lhs, const ::String& rhs) {
lhs << rhs._str;
return lhs;

View File

@ -1,9 +1,8 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <stdint.h> // uint8_t
#include <string.h> // strcmp, strlen...
#define PROGMEM
@ -24,19 +23,7 @@ inline uint8_t pgm_read_byte(const void* p) {
return *reinterpret_cast<const uint8_t*>(convertFlashToPtr(p));
}
inline void* pgm_read_ptr(const void* p) {
return *reinterpret_cast<void* const*>(convertFlashToPtr(p));
}
inline float pgm_read_float(const void* p) {
return *reinterpret_cast<const float*>(convertFlashToPtr(p));
}
inline uint32_t pgm_read_dword(const void* p) {
return *reinterpret_cast<const uint32_t*>(convertFlashToPtr(p));
}
#define ARDUINOJSON_DEFINE_STATIC_ARRAY(type, name, value) \
#define ARDUINOJSON_DEFINE_PROGMEM_ARRAY(type, name, value) \
static type const ARDUINOJSON_CONCAT2(name, _progmem)[] = value; \
static type const* name = reinterpret_cast<type const*>( \
convertPtrToFlash(ARDUINOJSON_CONCAT2(name, _progmem)));

View File

@ -1,5 +1,5 @@
# ArduinoJson - https://arduinojson.org
# Copyright Benoit Blanchon 2014-2021
# Copyright © 2014-2022, Benoit BLANCHON
# MIT License
add_executable(IntegrationTests

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
# ArduinoJson - https://arduinojson.org
# Copyright Benoit Blanchon 2014-2021
# Copyright © 2014-2022, Benoit BLANCHON
# MIT License
add_executable(JsonArrayTests
@ -17,7 +17,7 @@ add_executable(JsonArrayTests
size.cpp
std_string.cpp
subscript.cpp
undefined.cpp
unbound.cpp
)
add_test(JsonArray JsonArrayTests)

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
@ -40,7 +40,7 @@ TEST_CASE("JsonArray::add()") {
#ifdef HAS_VARIABLE_LENGTH_ARRAY
SECTION("vla") {
int i = 16;
size_t i = 16;
char vla[i];
strcpy(vla, "world");

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
@ -32,6 +32,56 @@ TEST_CASE("copyArray()") {
CHECK(std::string("[\"a\",\"b\",\"c\"]") == json);
}
SECTION("const char*[] -> JsonArray") {
DynamicJsonDocument doc(4096);
JsonArray array = doc.to<JsonArray>();
char json[32];
const char* source[] = {"a", "b", "c"};
bool ok = copyArray(source, array);
CHECK(ok);
serializeJson(array, json);
CHECK(std::string("[\"a\",\"b\",\"c\"]") == json);
}
SECTION("const char[][] -> JsonArray") {
DynamicJsonDocument doc(4096);
JsonArray array = doc.to<JsonArray>();
char json[32];
char source[][2] = {"a", "b", "c"};
bool ok = copyArray(source, array);
CHECK(ok);
serializeJson(array, json);
CHECK(std::string("[\"a\",\"b\",\"c\"]") == json);
}
SECTION("const char[][] -> JsonDocument") {
DynamicJsonDocument doc(4096);
char json[32];
char source[][2] = {"a", "b", "c"};
bool ok = copyArray(source, doc);
CHECK(ok);
serializeJson(doc, json);
CHECK(std::string("[\"a\",\"b\",\"c\"]") == json);
}
SECTION("const char[][] -> MemberProxy") {
DynamicJsonDocument doc(4096);
char json[32];
char source[][2] = {"a", "b", "c"};
bool ok = copyArray(source, doc["data"]);
CHECK(ok);
serializeJson(doc, json);
CHECK(std::string("{\"data\":[\"a\",\"b\",\"c\"]}") == json);
}
SECTION("int[] -> JsonDocument") {
DynamicJsonDocument doc(4096);
char json[32];
@ -174,6 +224,23 @@ TEST_CASE("copyArray()") {
CHECK("" == destination[3]);
}
SECTION("JsonArray -> char[N][]") {
DynamicJsonDocument doc(4096);
char json[] = "[\"a12345\",\"b123456\",\"c1234567\"]";
DeserializationError err = deserializeJson(doc, json);
CHECK(err == DeserializationError::Ok);
JsonArray array = doc.as<JsonArray>();
char destination[4][8] = {{0}};
size_t result = copyArray(array, destination);
CHECK(3 == result);
CHECK(std::string("a12345") == destination[0]);
CHECK(std::string("b123456") == destination[1]);
CHECK(std::string("c123456") == destination[2]); // truncated
CHECK(std::string("") == destination[3]);
}
SECTION("JsonDocument -> int[]") {
DynamicJsonDocument doc(4096);
char json[] = "[1,2,3]";

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
@ -135,7 +135,7 @@ TEST_CASE("JsonArray::operator[]") {
#ifdef HAS_VARIABLE_LENGTH_ARRAY
SECTION("set(VLA)") {
int i = 16;
size_t i = 16;
char vla[i];
strcpy(vla, "world");
@ -146,7 +146,7 @@ TEST_CASE("JsonArray::operator[]") {
}
SECTION("operator=(VLA)") {
int i = 16;
size_t i = 16;
char vla[i];
strcpy(vla, "world");

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
@ -7,7 +7,7 @@
using namespace Catch::Matchers;
TEST_CASE("Undefined JsonArray") {
TEST_CASE("Unbound JsonArray") {
JsonArray array;
SECTION("SubscriptFails") {

View File

@ -1,5 +1,5 @@
# ArduinoJson - https://arduinojson.org
# Copyright Benoit Blanchon 2014-2021
# Copyright © 2014-2022, Benoit BLANCHON
# MIT License
add_executable(JsonDeserializerTests

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
@ -11,14 +11,14 @@ void testStringification(DeserializationError error, std::string expected) {
void testBoolification(DeserializationError error, bool expected) {
// DeserializationError on left-hand side
CHECK(error == expected);
CHECK(error != !expected);
CHECK(!error == !expected);
CHECK(bool(error) == expected);
CHECK(bool(error) != !expected);
CHECK(!bool(error) == !expected);
// DeserializationError on right-hand side
CHECK(expected == error);
CHECK(!expected != error);
CHECK(!expected == !error);
CHECK(expected == bool(error));
CHECK(!expected != bool(error));
CHECK(!expected == !bool(error));
}
#define TEST_STRINGIFICATION(symbol) \
@ -70,34 +70,24 @@ TEST_CASE("DeserializationError") {
}
}
SECTION("Comparisons") {
SECTION("Use in a condition") {
DeserializationError invalidInput(DeserializationError::InvalidInput);
DeserializationError ok(DeserializationError::Ok);
SECTION("DeserializationError == bool") {
REQUIRE(invalidInput == true);
REQUIRE(ok == false);
SECTION("if (!err)") {
if (!invalidInput)
FAIL();
}
SECTION("bool == DeserializationError") {
REQUIRE(true == invalidInput);
REQUIRE(false == ok);
SECTION("if (err)") {
if (ok)
FAIL();
}
}
SECTION("DeserializationError != bool") {
REQUIRE(invalidInput != false);
REQUIRE(ok != true);
}
SECTION("bool != DeserializationError") {
REQUIRE(false != invalidInput);
REQUIRE(true != ok);
}
SECTION("Negations") {
REQUIRE(!invalidInput == false);
REQUIRE(!ok == true);
}
SECTION("Comparisons") {
DeserializationError invalidInput(DeserializationError::InvalidInput);
DeserializationError ok(DeserializationError::Ok);
SECTION("DeserializationError == Code") {
REQUIRE(invalidInput == DeserializationError::InvalidInput);

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#define ARDUINOJSON_ENABLE_COMMENTS 1
@ -366,7 +366,7 @@ TEST_CASE("Filtering") {
0
},
{
// bubble up element error even if array is skipped
// bubble up element error even if array is skipped
"[1,'2,3]",
"false",
10,
@ -375,7 +375,7 @@ TEST_CASE("Filtering") {
0
},
{
// bubble up member error even if object is skipped
// bubble up member error even if object is skipped
"{'hello':'worl}",
"false",
10,
@ -384,7 +384,7 @@ TEST_CASE("Filtering") {
0
},
{
// bubble up colon error even if object is skipped
// bubble up colon error even if object is skipped
"{'hello','world'}",
"false",
10,
@ -393,7 +393,7 @@ TEST_CASE("Filtering") {
0
},
{
// bubble up key error even if object is skipped
// bubble up key error even if object is skipped
"{'hello:1}",
"false",
10,
@ -404,7 +404,7 @@ TEST_CASE("Filtering") {
{
// detect invalid value in skipped object
"{'hello':!}",
"false",
"false",
10,
DeserializationError::InvalidInput,
"null",
@ -413,235 +413,235 @@ TEST_CASE("Filtering") {
{
// ignore invalid value in skipped object
"{'hello':\\}",
"false",
"false",
10,
DeserializationError::InvalidInput,
"null",
"null",
0
},
{
// check nesting limit even for ignored objects
"{}",
"false",
"false",
0,
DeserializationError::TooDeep,
"null",
"null",
0
},
{
// check nesting limit even for ignored objects
"{'hello':{}}",
"false",
"false",
1,
DeserializationError::TooDeep,
"null",
"null",
0
},
{
// check nesting limit even for ignored values in objects
"{'hello':{}}",
"{}",
"{}",
1,
DeserializationError::TooDeep,
"{}",
"{}",
JSON_OBJECT_SIZE(0)
},
{
// check nesting limit even for ignored arrays
"[]",
"false",
"false",
0,
DeserializationError::TooDeep,
"null",
"null",
0
},
{
// check nesting limit even for ignored arrays
"[[]]",
"false",
"false",
1,
DeserializationError::TooDeep,
"null",
"null",
0
},
{
// check nesting limit even for ignored values in arrays
"[[]]",
"[]",
"[]",
1,
DeserializationError::TooDeep,
"[]",
"[]",
JSON_ARRAY_SIZE(0)
},
{
// supports back-slash at the end of skipped string
"\"hell\\",
"false",
"false",
1,
DeserializationError::IncompleteInput,
"null",
"null",
0
},
{
// invalid comment at after an element in a skipped array
"[1/]",
"false",
"false",
10,
DeserializationError::InvalidInput,
"null",
"null",
0
},
{
// incomplete comment at after an element in a skipped array
"[1/*]",
"false",
"false",
10,
DeserializationError::IncompleteInput,
"null",
"null",
0
},
{
// missing comma in a skipped array
"[1 2]",
"false",
"false",
10,
DeserializationError::InvalidInput,
"null",
"null",
0
},
{
// invalid comment at the beginning of array
"[/1]",
"[false]",
"[false]",
10,
DeserializationError::InvalidInput,
"[]",
"[]",
JSON_ARRAY_SIZE(0)
},
{
// incomplete comment at the begining of an array
"[/*]",
"[false]",
"[false]",
10,
DeserializationError::IncompleteInput,
"[]",
"[]",
JSON_ARRAY_SIZE(0)
},
{
// invalid comment before key
"{/1:2}",
"{}",
"{}",
10,
DeserializationError::InvalidInput,
"{}",
"{}",
JSON_OBJECT_SIZE(0)
},
{
// incomplete comment before key
"{/*:2}",
"{}",
"{}",
10,
DeserializationError::IncompleteInput,
"{}",
"{}",
JSON_OBJECT_SIZE(0)
},
{
// invalid comment after key
"{\"example\"/1:2}",
"{}",
"{}",
10,
DeserializationError::InvalidInput,
"{}",
"{}",
JSON_OBJECT_SIZE(0)
},
{
// incomplete comment after key
"{\"example\"/*:2}",
"{}",
"{}",
10,
DeserializationError::IncompleteInput,
"{}",
"{}",
JSON_OBJECT_SIZE(0)
},
{
// invalid comment after colon
"{\"example\":/12}",
"{}",
"{}",
10,
DeserializationError::InvalidInput,
"{}",
"{}",
JSON_OBJECT_SIZE(0)
},
{
// incomplete comment after colon
"{\"example\":/*2}",
"{}",
"{}",
10,
DeserializationError::IncompleteInput,
"{}",
"{}",
JSON_OBJECT_SIZE(0)
},
{
// comment next to an integer
"{\"ignore\":1//,\"example\":2\n}",
"{\"example\":true}",
"{\"example\":true}",
10,
DeserializationError::Ok,
"{}",
"{}",
JSON_OBJECT_SIZE(0)
},
{
// invalid comment after opening brace of a skipped object
"{/1:2}",
"false",
"false",
10,
DeserializationError::InvalidInput,
"null",
"null",
0
},
{
// incomplete after opening brace of a skipped object
"{/*:2}",
"false",
"false",
10,
DeserializationError::IncompleteInput,
"null",
"null",
0
},
{
// invalid comment after key of a skipped object
"{\"example\"/:2}",
"false",
"false",
10,
DeserializationError::InvalidInput,
"null",
"null",
0
},
{
// incomplete after after key of a skipped object
"{\"example\"/*:2}",
"false",
"false",
10,
DeserializationError::IncompleteInput,
"null",
"null",
0
},
{
// invalid comment after value in a skipped object
"{\"example\":2/}",
"false",
"false",
10,
DeserializationError::InvalidInput,
"null",
"null",
0
},
{
// incomplete after after value of a skipped object
"{\"example\":2/*}",
"false",
"false",
10,
DeserializationError::IncompleteInput,
"null",
"null",
0
},
}; // clang-format on
@ -667,6 +667,20 @@ TEST_CASE("Filtering") {
}
}
TEST_CASE("Zero-copy mode") { // issue #1697
char input[] = "{\"include\":42,\"exclude\":666}";
StaticJsonDocument<256> filter;
filter["include"] = true;
StaticJsonDocument<256> doc;
DeserializationError err =
deserializeJson(doc, input, DeserializationOption::Filter(filter));
REQUIRE(err == DeserializationError::Ok);
CHECK(doc.as<std::string>() == "{\"include\":42}");
}
TEST_CASE("Overloads") {
StaticJsonDocument<256> doc;
StaticJsonDocument<256> filter;
@ -694,7 +708,7 @@ TEST_CASE("Overloads") {
#ifdef HAS_VARIABLE_LENGTH_ARRAY
SECTION("char[n], Filter") {
int i = 4;
size_t i = 4;
char vla[i];
strcpy(vla, "{}");
deserializeJson(doc, vla, Filter(filter));
@ -722,7 +736,7 @@ TEST_CASE("Overloads") {
#ifdef HAS_VARIABLE_LENGTH_ARRAY
SECTION("char[n], Filter, NestingLimit") {
int i = 4;
size_t i = 4;
char vla[i];
strcpy(vla, "{}");
deserializeJson(doc, vla, Filter(filter), NestingLimit(5));
@ -750,7 +764,7 @@ TEST_CASE("Overloads") {
#ifdef HAS_VARIABLE_LENGTH_ARRAY
SECTION("char[n], NestingLimit, Filter") {
int i = 4;
size_t i = 4;
char vla[i];
strcpy(vla, "{}");
deserializeJson(doc, vla, NestingLimit(5), Filter(filter));

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#define ARDUINOJSON_DECODE_UNICODE 1

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
@ -121,7 +121,7 @@ TEST_CASE("deserializeJson(std::istream&)") {
#ifdef HAS_VARIABLE_LENGTH_ARRAY
TEST_CASE("deserializeJson(VLA)") {
int i = 9;
size_t i = 9;
char vla[i];
strcpy(vla, "{\"a\":42}");

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#define ARDUINOJSON_DECODE_UNICODE 1

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#define ARDUINOJSON_USE_LONG_LONG 0

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
@ -279,6 +279,22 @@ TEST_CASE("deserialize JSON object") {
REQUIRE(err == DeserializationError::Ok);
REQUIRE(doc["a"] == 2);
}
SECTION("Repeated key with zero copy mode") { // issue #1697
char input[] = "{a:{b:{c:1}},a:2}";
DeserializationError err = deserializeJson(doc, input);
REQUIRE(err == DeserializationError::Ok);
REQUIRE(doc["a"] == 2);
}
SECTION("NUL in keys") { // we don't support NULs in keys
DeserializationError err =
deserializeJson(doc, "{\"x\\u0000a\":1,\"x\\u0000b\":2}");
REQUIRE(err == DeserializationError::Ok);
REQUIRE(doc.as<std::string>() == "{\"x\":2}");
}
}
SECTION("Should clear the JsonObject") {

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#define ARDUINOJSON_DECODE_UNICODE 1
@ -60,9 +60,8 @@ TEST_CASE("\\u0000") {
CHECK(result[4] == 'z');
CHECK(result[5] == 0);
// ArduinoJson strings doesn't store string length, so the following returns 2
// instead of 5 (issue #1646)
CHECK(doc.as<std::string>().size() == 2);
CHECK(doc.as<JsonString>().size() == 5);
CHECK(doc.as<std::string>().size() == 5);
}
TEST_CASE("Truncated JSON string") {
@ -97,12 +96,37 @@ TEST_CASE("Not enough room to save the key") {
DynamicJsonDocument doc(JSON_OBJECT_SIZE(1) + 8);
SECTION("Quoted string") {
REQUIRE(deserializeJson(doc, "{\"example\":1}") ==
DeserializationError::Ok);
REQUIRE(deserializeJson(doc, "{\"accuracy\":1}") ==
DeserializationError::NoMemory);
REQUIRE(deserializeJson(doc, "{\"hello\":1,\"world\"}") ==
DeserializationError::NoMemory); // fails in the second string
}
SECTION("Non-quoted string") {
REQUIRE(deserializeJson(doc, "{example:1}") == DeserializationError::Ok);
REQUIRE(deserializeJson(doc, "{accuracy:1}") ==
DeserializationError::NoMemory);
REQUIRE(deserializeJson(doc, "{hello:1,world}") ==
DeserializationError::NoMemory); // fails in the second string
}
}
TEST_CASE("Empty memory pool") {
// NOLINTNEXTLINE(clang-analyzer-optin.portability.UnixAPI)
DynamicJsonDocument doc(0);
SECTION("Input is const char*") {
REQUIRE(deserializeJson(doc, "\"hello\"") ==
DeserializationError::NoMemory);
REQUIRE(deserializeJson(doc, "\"\"") == DeserializationError::NoMemory);
}
SECTION("Input is const char*") {
char hello[] = "\"hello\"";
REQUIRE(deserializeJson(doc, hello) == DeserializationError::Ok);
char empty[] = "\"hello\"";
REQUIRE(deserializeJson(doc, empty) == DeserializationError::Ok);
}
}

View File

@ -1,14 +1,14 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
#include <stdlib.h> // malloc, free
#include <catch.hpp>
#include <sstream>
#include <utility>
using ARDUINOJSON_NAMESPACE::addPadding;
using ARDUINOJSON_NAMESPACE::move;
class SpyingAllocator {
public:
@ -78,7 +78,7 @@ TEST_CASE("BasicJsonDocument") {
BasicJsonDocument<SpyingAllocator> doc1(4096, log);
doc1.set(std::string("The size of this string is 32!!"));
BasicJsonDocument<SpyingAllocator> doc2(move(doc1));
BasicJsonDocument<SpyingAllocator> doc2(std::move(doc1));
REQUIRE(doc2.as<std::string>() == "The size of this string is 32!!");
REQUIRE(doc1.as<std::string>() == "null");
@ -89,7 +89,7 @@ TEST_CASE("BasicJsonDocument") {
}
#endif
SECTION("Copy assign") {
SECTION("Copy assign larger") {
{
BasicJsonDocument<SpyingAllocator> doc1(4096, log);
doc1.set(std::string("The size of this string is 32!!"));
@ -104,6 +104,36 @@ TEST_CASE("BasicJsonDocument") {
REQUIRE(log.str() == "A4096A8FA4096FF");
}
SECTION("Copy assign smaller") {
{
BasicJsonDocument<SpyingAllocator> doc1(1024, log);
doc1.set(std::string("The size of this string is 32!!"));
BasicJsonDocument<SpyingAllocator> doc2(4096, log);
doc2 = doc1;
REQUIRE(doc1.as<std::string>() == "The size of this string is 32!!");
REQUIRE(doc2.as<std::string>() == "The size of this string is 32!!");
REQUIRE(doc2.capacity() == 1024);
}
REQUIRE(log.str() == "A1024A4096FA1024FF");
}
SECTION("Copy assign same size") {
{
BasicJsonDocument<SpyingAllocator> doc1(1024, log);
doc1.set(std::string("The size of this string is 32!!"));
BasicJsonDocument<SpyingAllocator> doc2(1024, log);
doc2 = doc1;
REQUIRE(doc1.as<std::string>() == "The size of this string is 32!!");
REQUIRE(doc2.as<std::string>() == "The size of this string is 32!!");
REQUIRE(doc2.capacity() == 1024);
}
REQUIRE(log.str() == "A1024A1024FF");
}
#if ARDUINOJSON_HAS_RVALUE_REFERENCES
SECTION("Move assign") {
{
@ -111,7 +141,7 @@ TEST_CASE("BasicJsonDocument") {
doc1.set(std::string("The size of this string is 32!!"));
BasicJsonDocument<SpyingAllocator> doc2(8, log);
doc2 = move(doc1);
doc2 = std::move(doc1);
REQUIRE(doc2.as<std::string>() == "The size of this string is 32!!");
REQUIRE(doc1.as<std::string>() == "null");

View File

@ -1,5 +1,5 @@
# ArduinoJson - https://arduinojson.org
# Copyright Benoit Blanchon 2014-2021
# Copyright © 2014-2022, Benoit BLANCHON
# MIT License
add_executable(JsonDocumentTests
@ -19,6 +19,7 @@ add_executable(JsonDocumentTests
size.cpp
StaticJsonDocument.cpp
subscript.cpp
swap.cpp
)
add_test(JsonDocument JsonDocumentTests)

View File

@ -1,5 +1,5 @@
// ArduinoJson - https://arduinojson.org
// Copyright Benoit Blanchon 2014-2021
// Copyright © 2014-2022, Benoit BLANCHON
// MIT License
#include <ArduinoJson.h>
@ -138,27 +138,26 @@ TEST_CASE("DynamicJsonDocument constructor") {
}
TEST_CASE("DynamicJsonDocument assignment") {
SECTION("Copy assignment preserves the buffer when capacity is sufficient") {
SECTION("Copy assignment reallocates when capacity is smaller") {
DynamicJsonDocument doc1(1234);
deserializeJson(doc1, "{\"hello\":\"world\"}");
DynamicJsonDocument doc2(8);
DynamicJsonDocument doc2(doc1.capacity());
doc2 = doc1;
REQUIRE_JSON(doc2, "{\"hello\":\"world\"}");
REQUIRE(doc2.capacity() == doc1.capacity());
}
SECTION("Copy assignment realloc the buffer when capacity is insufficient") {
DynamicJsonDocument doc1(1234);
SECTION("Copy assignment reallocates when capacity is larger") {
DynamicJsonDocument doc1(100);
deserializeJson(doc1, "{\"hello\":\"world\"}");
DynamicJsonDocument doc2(8);
DynamicJsonDocument doc2(1234);
REQUIRE(doc2.capacity() < doc1.memoryUsage());
doc2 = doc1;
REQUIRE(doc2.capacity() >= doc1.memoryUsage());
REQUIRE_JSON(doc2, "{\"hello\":\"world\"}");
REQUIRE(doc2.capacity() == doc1.capacity());
}
SECTION("Assign from StaticJsonDocument") {

Some files were not shown because too many files have changed in this diff Show More