forked from bblanchon/ArduinoJson
Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
ecbc8e85d4 | |||
4d00ed9efc | |||
cd5566cd40 | |||
52d8a65cbc | |||
420221f078 | |||
082ae69e86 | |||
976a6d7594 | |||
40daf56b5a | |||
31ce648e63 | |||
4ba9c1b0c0 | |||
19c5bb7f15 | |||
cb850bc1b1 | |||
481e4d2ffb | |||
9e9015f4b9 | |||
74601b2585 | |||
9bb3f4051d |
@ -1,18 +0,0 @@
|
||||
{
|
||||
"name": "Clang 11",
|
||||
"image": "conanio/clang11",
|
||||
"runArgs": [
|
||||
"--name=ArduinoJson-clang11"
|
||||
],
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"ms-vscode.cmake-tools"
|
||||
],
|
||||
"settings": {
|
||||
"cmake.generator": "Unix Makefiles",
|
||||
"cmake.buildDirectory": "/tmp/build"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
FROM ubuntu:22.04
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y cmake git clang-13 libc++-13-dev libc++abi-13-dev
|
||||
ENV CC=clang-13 CXX=clang++-13
|
@ -1,20 +0,0 @@
|
||||
{
|
||||
"name": "Clang 13",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile"
|
||||
},
|
||||
"runArgs": [
|
||||
"--name=ArduinoJson-clang13"
|
||||
],
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"ms-vscode.cmake-tools"
|
||||
],
|
||||
"settings": {
|
||||
"cmake.generator": "Unix Makefiles",
|
||||
"cmake.buildDirectory": "/tmp/build"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
FROM ubuntu:22.04
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y cmake git clang-14 libc++-14-dev libc++abi-14-dev
|
||||
ENV CC=clang-14 CXX=clang++-14
|
@ -1,20 +0,0 @@
|
||||
{
|
||||
"name": "Clang 14",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile"
|
||||
},
|
||||
"runArgs": [
|
||||
"--name=ArduinoJson-clang14"
|
||||
],
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"ms-vscode.cmake-tools"
|
||||
],
|
||||
"settings": {
|
||||
"cmake.generator": "Unix Makefiles",
|
||||
"cmake.buildDirectory": "/tmp/build"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
FROM ubuntu:22.04
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y cmake git clang-15 libc++-15-dev libc++abi-15-dev
|
||||
ENV CC=clang-15 CXX=clang++-15
|
@ -1,20 +0,0 @@
|
||||
{
|
||||
"name": "Clang 15",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile"
|
||||
},
|
||||
"runArgs": [
|
||||
"--name=ArduinoJson-clang15"
|
||||
],
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"ms-vscode.cmake-tools"
|
||||
],
|
||||
"settings": {
|
||||
"cmake.generator": "Unix Makefiles",
|
||||
"cmake.buildDirectory": "/tmp/build"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
FROM ubuntu:22.04
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y cmake git clang-16 libc++-16-dev libc++abi-16-dev
|
||||
ENV CC=clang-16 CXX=clang++-16
|
@ -1,20 +0,0 @@
|
||||
{
|
||||
"name": "Clang 16",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile"
|
||||
},
|
||||
"runArgs": [
|
||||
"--name=ArduinoJson-clang16"
|
||||
],
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"ms-vscode.cmake-tools"
|
||||
],
|
||||
"settings": {
|
||||
"cmake.generator": "Unix Makefiles",
|
||||
"cmake.buildDirectory": "/tmp/build"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
FROM ubuntu:24.04
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y cmake git clang-17 libc++-17-dev libc++abi-17-dev
|
||||
ENV CC=clang-17 CXX=clang++-17
|
@ -1,20 +0,0 @@
|
||||
{
|
||||
"name": "Clang 17",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile"
|
||||
},
|
||||
"runArgs": [
|
||||
"--name=ArduinoJson-clang17"
|
||||
],
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"ms-vscode.cmake-tools"
|
||||
],
|
||||
"settings": {
|
||||
"cmake.generator": "Unix Makefiles",
|
||||
"cmake.buildDirectory": "/tmp/build"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
FROM ubuntu:22.04
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y cmake git g++-12
|
@ -1,20 +0,0 @@
|
||||
{
|
||||
"name": "GCC 12",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile",
|
||||
},
|
||||
"runArgs": [
|
||||
"--name=ArduinoJson-gcc12"
|
||||
],
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"ms-vscode.cmake-tools"
|
||||
],
|
||||
"settings": {
|
||||
"cmake.generator": "Unix Makefiles",
|
||||
"cmake.buildDirectory": "/tmp/build"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
{
|
||||
"name": "GCC 4.8",
|
||||
"image": "conanio/gcc48",
|
||||
"runArgs": [
|
||||
"--name=ArduinoJson-gcc48"
|
||||
],
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"ms-vscode.cmake-tools",
|
||||
"josetr.cmake-language-support-vscode",
|
||||
"ms-vscode.cpptools"
|
||||
],
|
||||
"settings": {
|
||||
"cmake.generator": "Unix Makefiles",
|
||||
"cmake.buildDirectory": "/tmp/build"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
4
.github/ISSUE_TEMPLATE/bug_report.md
vendored
4
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -14,7 +14,7 @@ Before opening a bug report, please use the ArduinoJson Troubleshooter as it may
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**Troubleshooter report**
|
||||
Here is the report generated by the [ArduinoJson Troubleshooter](https://arduinojson.org/v7/troubleshooter/):
|
||||
Here is the report generated by the [ArduinoJson Troubleshooter](https://arduinojson.org/v6/troubleshooter/):
|
||||
[Paste the report here]
|
||||
|
||||
**Environment**
|
||||
@ -27,7 +27,7 @@ Here is the environment that I used:
|
||||
Here is a small snippet that reproduces the issue.
|
||||
|
||||
```c++
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(1024);
|
||||
|
||||
DeserializationError error = deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||
|
||||
|
4
.github/ISSUE_TEMPLATE/config.yml
vendored
4
.github/ISSUE_TEMPLATE/config.yml
vendored
@ -1,8 +1,8 @@
|
||||
blank_issues_enabled: true
|
||||
contact_links:
|
||||
- name: 👨🏫 ArduinoJson Assistant
|
||||
url: https://arduinojson.org/v7/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/v7/troubleshooter/
|
||||
url: https://arduinojson.org/v6/troubleshooter/
|
||||
about: An online tool that helps you diagnose the most common issues with ArduinoJson.
|
||||
|
4
.github/ISSUE_TEMPLATE/help.md
vendored
4
.github/ISSUE_TEMPLATE/help.md
vendored
@ -15,7 +15,7 @@ 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/v7/troubleshooter/):
|
||||
Here is the report generated by the [ArduinoJson Troubleshooter](https://arduinojson.org/v6/troubleshooter/):
|
||||
[Paste the report here]
|
||||
|
||||
**Environment**
|
||||
@ -28,7 +28,7 @@ Here is the environment that I'm using':
|
||||
Here is a small snippet that demonstrate the problem.
|
||||
|
||||
```c++
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(1024);
|
||||
|
||||
DeserializationError error = deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||
|
||||
|
221
.github/workflows/ci.yml
vendored
221
.github/workflows/ci.yml
vendored
@ -2,19 +2,15 @@ name: Continuous Integration
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
name: Lint
|
||||
runs-on: ubuntu-22.04
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Install
|
||||
run: sudo apt-get install -y clang-format
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
- name: Symlinks
|
||||
run: find * -type l -printf "::error::%p is a symlink. This is forbidden by the Arduino Library Specification." -exec false {} +
|
||||
- name: Clang-format
|
||||
@ -37,7 +33,6 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- gcc: "4.8"
|
||||
- gcc: "5"
|
||||
- gcc: "6"
|
||||
- gcc: "7"
|
||||
@ -49,102 +44,67 @@ jobs:
|
||||
- gcc: "10"
|
||||
cxxflags: -funsigned-char # Issue #1715
|
||||
- gcc: "11"
|
||||
- gcc: "12"
|
||||
steps:
|
||||
- name: Workaround for actions/runner-images#9491
|
||||
run: sudo sysctl vm.mmap_rnd_bits=28
|
||||
|
||||
- name: Install
|
||||
run: |
|
||||
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5 3B4FE6ACC0B21F32
|
||||
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ xenial main universe'
|
||||
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ bionic main universe'
|
||||
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ focal main universe'
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y gcc-${{ matrix.gcc }} g++-${{ matrix.gcc }}
|
||||
timeout-minutes: 5
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
timeout-minutes: 1
|
||||
|
||||
uses: actions/checkout@v3
|
||||
- name: Configure
|
||||
run: cmake -DCMAKE_BUILD_TYPE=Debug .
|
||||
env:
|
||||
CC: gcc-${{ matrix.gcc }}
|
||||
CXX: g++-${{ matrix.gcc }}
|
||||
CXXFLAGS: ${{ matrix.cxxflags }}
|
||||
timeout-minutes: 1
|
||||
|
||||
- name: Build
|
||||
run: cmake --build .
|
||||
timeout-minutes: 10
|
||||
|
||||
- name: Test
|
||||
run: ctest --output-on-failure -C Debug .
|
||||
run: |
|
||||
echo "## CTest output" >> $GITHUB_STEP_SUMMARY
|
||||
echo '```' >> $GITHUB_STEP_SUMMARY
|
||||
ctest --output-on-failure -C Debug . | tee -a $GITHUB_STEP_SUMMARY
|
||||
echo '```' >> $GITHUB_STEP_SUMMARY
|
||||
env:
|
||||
UBSAN_OPTIONS: print_stacktrace=1
|
||||
timeout-minutes: 2
|
||||
|
||||
clang:
|
||||
name: Clang
|
||||
needs: lint
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- clang: "3.8"
|
||||
cxxflags: "-stdlib=libc++"
|
||||
- clang: "3.9"
|
||||
runner: ubuntu-20.04
|
||||
archive: bionic
|
||||
cxxflags: "-stdlib=libc++"
|
||||
- clang: "4.0"
|
||||
runner: ubuntu-20.04
|
||||
archive: bionic
|
||||
cxxflags: "-stdlib=libc++"
|
||||
- clang: "5.0"
|
||||
runner: ubuntu-20.04
|
||||
archive: bionic
|
||||
- clang: "6.0"
|
||||
runner: ubuntu-20.04
|
||||
archive: bionic
|
||||
- clang: "7"
|
||||
runner: ubuntu-20.04
|
||||
- clang: "8"
|
||||
cxxflags: -fsanitize=leak -fno-sanitize-recover=all
|
||||
runner: ubuntu-20.04
|
||||
- clang: "9"
|
||||
cxxflags: -fsanitize=undefined -fno-sanitize-recover=all
|
||||
runner: ubuntu-20.04
|
||||
- clang: "10"
|
||||
cxxflags: -fsanitize=address -fno-sanitize-recover=all
|
||||
runner: ubuntu-20.04
|
||||
- clang: "11"
|
||||
runner: ubuntu-22.04
|
||||
- clang: "12"
|
||||
runner: ubuntu-22.04
|
||||
- clang: "13"
|
||||
runner: ubuntu-22.04
|
||||
- clang: "14"
|
||||
runner: ubuntu-22.04
|
||||
- clang: "15"
|
||||
runner: ubuntu-22.04
|
||||
runs-on: ${{ matrix.runner }}
|
||||
steps:
|
||||
- name: Add archive repositories
|
||||
if: matrix.archive
|
||||
run: |
|
||||
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ ${{ matrix.archive }} main'
|
||||
sudo add-apt-repository -yn 'deb http://archive.ubuntu.com/ubuntu/ ${{ matrix.archive }} universe'
|
||||
- name: Install Clang ${{ matrix.clang }}
|
||||
- name: Install
|
||||
run: |
|
||||
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/ bionic main'
|
||||
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: Install libc++ ${{ matrix.clang }}
|
||||
if: matrix.clang >= 11
|
||||
run: sudo apt-get install -y libc++-${{ matrix.clang }}-dev libc++abi-${{ matrix.clang }}-dev
|
||||
- name: Install libunwind ${{ matrix.clang }}
|
||||
if: matrix.clang == 12 # dependency is missing in Ubuntu 22.04
|
||||
run: sudo apt-get install -y libunwind-${{ matrix.clang }}-dev
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
- name: Configure
|
||||
run: cmake -DCMAKE_BUILD_TYPE=Debug .
|
||||
env:
|
||||
@ -152,11 +112,15 @@ jobs:
|
||||
CXX: clang++-${{ matrix.clang }}
|
||||
CXXFLAGS: >-
|
||||
${{ matrix.cxxflags }}
|
||||
${{ matrix.clang < 11 && '-I/usr/lib/llvm-10/include/c++/v1/' || '' }}
|
||||
${{ contains(matrix.cxxflags, 'libc++') && '-I/usr/lib/llvm-10/include/c++/v1/' || '' }}
|
||||
- name: Build
|
||||
run: cmake --build .
|
||||
- name: Test
|
||||
run: ctest --output-on-failure -C Debug .
|
||||
run: |
|
||||
echo "## CTest output" >> $GITHUB_STEP_SUMMARY
|
||||
echo '```' >> $GITHUB_STEP_SUMMARY
|
||||
ctest --output-on-failure -C Debug . | tee -a $GITHUB_STEP_SUMMARY
|
||||
echo '```' >> $GITHUB_STEP_SUMMARY
|
||||
env:
|
||||
UBSAN_OPTIONS: print_stacktrace=1
|
||||
|
||||
@ -170,7 +134,7 @@ jobs:
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y g++-multilib gcc-avr avr-libc
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
- name: AVR
|
||||
run: avr-g++ -std=c++11 -Isrc extras/conf_test/avr.cpp
|
||||
- name: GCC 32-bit
|
||||
@ -188,7 +152,7 @@ jobs:
|
||||
needs: [gcc, clang]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
- name: 32-bit
|
||||
run: |
|
||||
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars32.bat"
|
||||
@ -203,20 +167,17 @@ jobs:
|
||||
xcode:
|
||||
name: XCode
|
||||
needs: clang
|
||||
runs-on: macos-13
|
||||
runs-on: macos-11
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- xcode: "14.1"
|
||||
- xcode: "14.2"
|
||||
- xcode: "14.3.1"
|
||||
- xcode: "15.0.1"
|
||||
- xcode: "15.1"
|
||||
- xcode: "15.2"
|
||||
- xcode: "11.7"
|
||||
- xcode: "12.4"
|
||||
- xcode: "13.2.1"
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
- name: Select XCode version
|
||||
run: sudo xcode-select --switch /Applications/Xcode_${{ matrix.xcode }}.app
|
||||
- name: Configure
|
||||
@ -238,7 +199,7 @@ jobs:
|
||||
# runs-on: ${{ matrix.os }}
|
||||
# steps:
|
||||
# - name: Checkout
|
||||
# uses: actions/checkout@v4
|
||||
# uses: actions/checkout@v3
|
||||
# - name: Configure
|
||||
# run: cmake -DCMAKE_BUILD_TYPE=Debug .
|
||||
# - name: Build
|
||||
@ -260,7 +221,7 @@ jobs:
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
- name: Install arduino-cli
|
||||
run: curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sh
|
||||
- name: Install core
|
||||
@ -333,14 +294,14 @@ jobs:
|
||||
conf_test: esp8266
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
- name: Set up cache for pip
|
||||
uses: actions/cache@v4
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/.cache/pip
|
||||
key: ${{ runner.os }}-pip
|
||||
- name: Set up Python 3.x
|
||||
uses: actions/setup-python@v5
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.x"
|
||||
- name: Install PlatformIO
|
||||
@ -352,7 +313,7 @@ jobs:
|
||||
if: ${{ matrix.platform == 'nordicnrf52' }}
|
||||
run: find examples/ -name '*.ino' -exec sed -i 's/\(#include <ArduinoJson.h>\)/\1\n#include <Adafruit_TinyUSB.h>/' {} +
|
||||
- name: Set up cache for platformio
|
||||
uses: actions/cache@v4
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/.platformio
|
||||
key: ${{ runner.os }}-platformio-${{ matrix.platform }}
|
||||
@ -401,9 +362,9 @@ jobs:
|
||||
- board: argon
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
- name: Install Particle CLI
|
||||
run: sudo npm install -g particle-cli particle-usb
|
||||
run: sudo npm install -g particle-cli
|
||||
- name: Login to Particle
|
||||
run: particle login -t "${{ secrets.PARTICLE_TOKEN }}"
|
||||
- name: Compile
|
||||
@ -419,7 +380,7 @@ jobs:
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y g++-arm-linux-gnueabihf
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
- name: Configure
|
||||
run: cmake .
|
||||
env:
|
||||
@ -436,13 +397,13 @@ jobs:
|
||||
- name: Install
|
||||
run: sudo apt-get install -y lcov ninja-build
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
- name: Configure
|
||||
run: cmake -G Ninja -DCOVERAGE=true .
|
||||
- name: Build
|
||||
run: ninja
|
||||
- name: Test
|
||||
run: ctest --output-on-failure -LE 'WillFail|Fuzzing' -T test
|
||||
run: ctest -LE 'WillFail|Fuzzing' -T test
|
||||
- name: lcov --capture
|
||||
run: lcov --capture --no-external --directory . --output-file coverage.info
|
||||
- name: lcov --remove
|
||||
@ -450,12 +411,12 @@ jobs:
|
||||
- name: genhtml
|
||||
run: mkdir coverage && genhtml coverage_filtered.info -o coverage -t ArduinoJson
|
||||
- name: Upload HTML report
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: Coverage report
|
||||
path: coverage
|
||||
- name: Upload to Coveralls
|
||||
uses: coverallsapp/github-action@v2
|
||||
uses: coverallsapp/github-action@master
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
path-to-lcov: coverage_filtered.info
|
||||
@ -470,16 +431,16 @@ jobs:
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y valgrind ninja-build
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
- name: Configure
|
||||
run: cmake -G Ninja -D MEMORYCHECK_COMMAND_OPTIONS="--error-exitcode=1 --leak-check=full" .
|
||||
- name: Build
|
||||
run: ninja
|
||||
- name: Memcheck
|
||||
run: ctest --output-on-failure -LE WillFail -T memcheck
|
||||
run: ctest -LE WillFail -T memcheck
|
||||
id: memcheck
|
||||
- name: MemoryChecker.*.log
|
||||
run: cat Testing/Temporary/MemoryChecker.*.log > $GITHUB_STEP_SUMMARY
|
||||
run: cat Testing/Temporary/MemoryChecker.*.log
|
||||
if: failure()
|
||||
|
||||
clang-tidy:
|
||||
@ -490,7 +451,7 @@ jobs:
|
||||
- name: Install
|
||||
run: sudo apt-get install -y clang-tidy cmake ninja-build
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
- name: Configure
|
||||
run: cmake -G Ninja -DCMAKE_CXX_CLANG_TIDY="clang-tidy-10;--warnings-as-errors=*" -DCMAKE_BUILD_TYPE=Debug .
|
||||
env:
|
||||
@ -499,51 +460,73 @@ jobs:
|
||||
- name: Check
|
||||
run: cmake --build . -- -k 0
|
||||
|
||||
amalgamate:
|
||||
amalgamate-h:
|
||||
needs: gcc
|
||||
name: Amalgamate ArduinoJson.h
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup
|
||||
uses: actions/checkout@v3
|
||||
- name: Amalgamate
|
||||
id: amalgamate
|
||||
run: |
|
||||
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
||||
VERSION=${GITHUB_REF#refs/tags/}
|
||||
else
|
||||
VERSION=${GITHUB_SHA::7}
|
||||
fi
|
||||
echo "ARDUINOJSON_H=ArduinoJson-$VERSION.h" >> $GITHUB_ENV
|
||||
echo "ARDUINOJSON_HPP=ArduinoJson-$VERSION.hpp" >> $GITHUB_ENV
|
||||
- name: Amalgamate ArduinoJson.h
|
||||
run: extras/scripts/build-single-header.sh "src/ArduinoJson.h" "$ARDUINOJSON_H"
|
||||
- name: Amalgamate ArduinoJson.hpp
|
||||
run: extras/scripts/build-single-header.sh "src/ArduinoJson.hpp" "$ARDUINOJSON_HPP"
|
||||
INPUT=src/ArduinoJson.h
|
||||
OUTPUT=ArduinoJson-$VERSION.h
|
||||
extras/scripts/build-single-header.sh "$INPUT" "$OUTPUT"
|
||||
echo "filename=${OUTPUT}" >> $GITHUB_OUTPUT
|
||||
- name: Smoke test
|
||||
run: |
|
||||
g++ -x c++ - <<END
|
||||
#include "${{ steps.amalgamate.outputs.filename }}"
|
||||
int main() {
|
||||
StaticJsonDocument<300> doc;
|
||||
deserializeJson(doc, "{}");
|
||||
}
|
||||
END
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: Single headers
|
||||
path: |
|
||||
${{ env.ARDUINOJSON_H }}
|
||||
${{ env.ARDUINOJSON_HPP }}
|
||||
- name: Smoke test ArduinoJson.h
|
||||
path: ${{ steps.amalgamate.outputs.filename }}
|
||||
|
||||
amalgamate-hpp:
|
||||
needs: gcc
|
||||
name: Amalgamate ArduinoJson.hpp
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Amalgamate
|
||||
id: amalgamate
|
||||
run: |
|
||||
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
||||
VERSION=${GITHUB_REF#refs/tags/}
|
||||
else
|
||||
VERSION=${GITHUB_SHA::7}
|
||||
fi
|
||||
INPUT=src/ArduinoJson.hpp
|
||||
OUTPUT=ArduinoJson-$VERSION.hpp
|
||||
extras/scripts/build-single-header.sh "$INPUT" "$OUTPUT"
|
||||
echo "filename=${OUTPUT}" >> $GITHUB_OUTPUT
|
||||
- name: Smoke test
|
||||
run: |
|
||||
g++ -x c++ - <<END
|
||||
#include "$ARDUINOJSON_H"
|
||||
#include "${{ steps.amalgamate.outputs.filename }}"
|
||||
int main() {
|
||||
JsonDocument doc;
|
||||
deserializeJson(doc, "{}");
|
||||
}
|
||||
END
|
||||
- name: Smoke test ArduinoJson.hpp
|
||||
run: |
|
||||
g++ -x c++ - <<END
|
||||
#include "$ARDUINOJSON_HPP"
|
||||
int main() {
|
||||
ArduinoJson::JsonDocument doc;
|
||||
ArduinoJson::StaticJsonDocument<300> doc;
|
||||
deserializeJson(doc, "{}");
|
||||
}
|
||||
END
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: Single headers
|
||||
path: ${{ steps.amalgamate.outputs.filename }}
|
||||
|
||||
esp-idf:
|
||||
needs: gcc
|
||||
@ -551,14 +534,14 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Setup cache
|
||||
uses: actions/cache@v4
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ~/.espressif
|
||||
key: ${{ runner.os }}-esp-idf
|
||||
- name: Checkout ArduinoJson
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
- name: Checkout ESP-IDF
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
repository: espressif/esp-idf
|
||||
path: esp-idf
|
||||
@ -588,10 +571,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v3
|
||||
uses: github/codeql-action/init@v2
|
||||
with:
|
||||
languages: cpp
|
||||
|
||||
@ -601,6 +584,6 @@ jobs:
|
||||
cmake --build .
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v3
|
||||
uses: github/codeql-action/analyze@v2
|
||||
with:
|
||||
category: "/language:cpp"
|
||||
|
2
.github/workflows/lock.yml
vendored
2
.github/workflows/lock.yml
vendored
@ -8,7 +8,7 @@ jobs:
|
||||
lock:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: dessant/lock-threads@v5
|
||||
- uses: dessant/lock-threads@v4
|
||||
with:
|
||||
github-token: ${{ github.token }}
|
||||
issue-inactive-days: 30
|
||||
|
35
.github/workflows/release.yml
vendored
35
.github/workflows/release.yml
vendored
@ -16,7 +16,7 @@ jobs:
|
||||
echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
||||
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
- name: Write release body
|
||||
id: body
|
||||
run: |
|
||||
@ -35,12 +35,18 @@ jobs:
|
||||
FILENAME=ArduinoJson-${{ steps.init.outputs.tag }}.hpp
|
||||
extras/scripts/build-single-header.sh src/ArduinoJson.hpp "$FILENAME"
|
||||
echo "filename=$FILENAME" >> $GITHUB_OUTPUT
|
||||
- name: Create Arduino package
|
||||
id: arduino
|
||||
run: |
|
||||
FILENAME=ArduinoJson-${{ steps.init.outputs.tag }}.zip
|
||||
extras/scripts/build-arduino-package.sh . "$FILENAME"
|
||||
echo "filename=$FILENAME" >> $GITHUB_OUTPUT
|
||||
- name: Create release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
bodyFile: ${{ steps.body.outputs.filename }}
|
||||
name: ArduinoJson ${{ steps.init.outputs.version }}
|
||||
artifacts: ${{ steps.amalgamate_h.outputs.filename }},${{ steps.amalgamate_hpp.outputs.filename }}
|
||||
artifacts: ${{ steps.amalgamate_h.outputs.filename }},${{ steps.amalgamate_hpp.outputs.filename }},${{ steps.arduino.outputs.filename }}
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
idf:
|
||||
@ -48,7 +54,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
- name: Upload component to the component registry
|
||||
uses: espressif/upload-components-ci-action@v1
|
||||
with:
|
||||
@ -61,27 +67,12 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Install
|
||||
run: npm install -g particle-cli particle-usb
|
||||
run: npm install -g particle-cli
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v3
|
||||
- name: Login
|
||||
run: particle login --token ${{ secrets.PARTICLE_TOKEN }}
|
||||
timeout-minutes: 1
|
||||
- name: Publish
|
||||
run: bash -eux extras/scripts/publish-particle-library.sh
|
||||
|
||||
platformio:
|
||||
name: PlatformIO
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Set up Python 3.x
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.x"
|
||||
- name: Install PlatformIO
|
||||
run: pip install platformio
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Publish
|
||||
run: pio pkg publish --no-interactive --no-notify
|
||||
env:
|
||||
PLATFORMIO_AUTH_TOKEN: ${{ secrets.PLATFORMIO_AUTH_TOKEN }}
|
||||
timeout-minutes: 5
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include "src/ArduinoJson.h"
|
||||
|
940
CHANGELOG.md
940
CHANGELOG.md
@ -1,186 +1,850 @@
|
||||
ArduinoJson: change log
|
||||
=======================
|
||||
|
||||
v7.2.0 (2024-09-18)
|
||||
------
|
||||
HEAD
|
||||
----
|
||||
|
||||
* Store object members with two slots: one for the key and one for the value
|
||||
* Store 64-bit numbers (`double` and `long long`) in an additional slot
|
||||
* Reduce the slot size (see table below)
|
||||
* Improve message when user forgets third arg of `serializeJson()` et al.
|
||||
* Set `ARDUINOJSON_USE_DOUBLE` to `0` by default on 8-bit architectures
|
||||
* Deprecate `containsKey()` in favor of `doc["key"].is<T>()`
|
||||
* Add support for escape sequence `\'` (issue #2124)
|
||||
* Fix compatibility with the Blynk libary (issue #1914)
|
||||
|
||||
| Architecture | before | after |
|
||||
|--------------|----------|----------|
|
||||
| 8-bit | 8 bytes | 6 bytes |
|
||||
| 32-bit | 16 bytes | 8 bytes |
|
||||
| 64-bit | 24 bytes | 16 bytes |
|
||||
v6.21.2 (2023-04-12)
|
||||
-------
|
||||
|
||||
* Fix compatibility with the Zephyr Project (issue #1905)
|
||||
* Allow using PROGMEM outside of Arduino (issue #1903)
|
||||
* Set default for `ARDUINOJSON_ENABLE_PROGMEM` to `1` on AVR
|
||||
|
||||
v6.21.1 (2023-03-27)
|
||||
-------
|
||||
|
||||
* Double speed of `DynamicJsonDocument::garbageCollect()`
|
||||
* Fix compatibility with GCC 5.2 (issue #1897)
|
||||
|
||||
v6.21.0 (2023-03-14)
|
||||
-------
|
||||
|
||||
* Drop support for C++98/C++03. Minimum required is C++11.
|
||||
* Remove `ARDUINOJSON_NAMESPACE`; use `ArduinoJson` instead.
|
||||
* Make string support generic (issue #1807)
|
||||
|
||||
v6.20.1 (2023-02-08)
|
||||
-------
|
||||
|
||||
* Remove explicit exclusion of `as<char*>()` and `as<char>()` (issue #1860)
|
||||
If you try to call them, you'll now get the same error message as any unsupported type.
|
||||
You could also add a custom converter for `char*` and `char`.
|
||||
|
||||
v6.20.0 (2022-12-26)
|
||||
-------
|
||||
|
||||
* Add `JsonVariant::shallowCopy()` (issue #1343)
|
||||
* Fix `9.22337e+18 is outside the range of representable values of type 'long'`
|
||||
* Fix comparison operators for `JsonArray`, `JsonArrayConst`, `JsonObject`, and `JsonObjectConst`
|
||||
* Fix lax parsing of `true`, `false`, and `null` (issue #1781)
|
||||
* Remove undocumented `accept()` functions
|
||||
* Rename `addElement()` to `add()`
|
||||
* Remove `getElement()`, `getOrAddElement()`, `getMember()`, and `getOrAddMember()`
|
||||
* Remove undocumented `JsonDocument::data()` and `JsonDocument::memoryPool()`
|
||||
* Remove undocumented `JsonArrayIterator::internal()` and `JsonObjectIterator::internal()`
|
||||
* Rename things in `ARDUINOJSON_NAMESPACE` to match the public names
|
||||
* Add documentation to most public symbols
|
||||
* Remove support for naked `char` (was deprecated since 6.18.0)
|
||||
|
||||
> ### BREAKING CHANGES
|
||||
>
|
||||
> After being on the death row for years, the `containsKey()` method has finally been deprecated.
|
||||
> You should replace `doc.containsKey("key")` with `doc["key"].is<T>()`, which not only checks that the key exists but also that the value is of the expected type.
|
||||
> This release hides `JsonVariant`'s functions that were only intended for internal use.
|
||||
> If you were using them in your programs, you must replace with `operator[]` and `to<JsonVariant>()`, like so:
|
||||
>
|
||||
> ```cpp
|
||||
> // Before
|
||||
> if (doc.containsKey("value")) {
|
||||
> int value = doc["value"];
|
||||
> // ...
|
||||
> }
|
||||
> ```c++
|
||||
> // before
|
||||
> JsonVariant a = variant.getElement(idx);
|
||||
> JsonVariant b = variant.getOrAddElement(idx);
|
||||
> JsonVariant c = variant.getMember(key);
|
||||
> JsonVariant d = variant.getOrAddMember(key);
|
||||
>
|
||||
> // After
|
||||
> if (doc["value"].is<int>()) {
|
||||
> int value = doc["value"];
|
||||
> // ...
|
||||
> }
|
||||
> // after
|
||||
> JsonVariant a = variant[idx];
|
||||
> JsonVariant b = idx < variant.size() ? variant[idx] : variant[idx].to<JsonVariant>();
|
||||
> JsonVariant c = variant[key];
|
||||
> JsonVariant d = variant.containsKey(key) ? variant[key] : variant[key].to<JsonVariant>();
|
||||
> ```
|
||||
|
||||
v7.1.0 (2024-06-27)
|
||||
------
|
||||
v6.19.4 (2022-04-05)
|
||||
-------
|
||||
|
||||
* Add `ARDUINOJSON_STRING_LENGTH_SIZE` to the namespace name
|
||||
* Add support for MsgPack binary (PR #2078 by @Sanae6)
|
||||
* Add support for MsgPack extension
|
||||
* Make string support even more generic (PR #2084 by @d-a-v)
|
||||
* Optimize `deserializeMsgPack()`
|
||||
* Allow using a `JsonVariant` as a key or index (issue #2080)
|
||||
Note: works only for reading, not for writing
|
||||
* Support `ElementProxy` and `MemberProxy` in `JsonDocument`'s constructor
|
||||
* Don't add partial objects when allocation fails (issue #2081)
|
||||
* Read MsgPack's 64-bit integers even if `ARDUINOJSON_USE_LONG_LONG` is `0`
|
||||
(they are set to `null` if they don't fit in a `long`)
|
||||
* Add `ElementProxy::memoryUsage()`
|
||||
* Add `MemberProxy::memoryUsage()` (issue #1730)
|
||||
* Add implicit conversion from `JsonDocument` to `JsonVariant`
|
||||
* Fix comparisons operators with `const JsonDocument&`
|
||||
|
||||
v7.0.4 (2024-03-12)
|
||||
------
|
||||
v6.19.3 (2022-03-08)
|
||||
-------
|
||||
|
||||
* Make `JSON_STRING_SIZE(N)` return `N+1` to fix third-party code (issue #2054)
|
||||
* 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)
|
||||
|
||||
v7.0.3 (2024-02-05)
|
||||
------
|
||||
v6.19.2 (2022-02-14)
|
||||
-------
|
||||
|
||||
* Improve error messages when using `char` or `char*` (issue #2043)
|
||||
* Reduce stack consumption (issue #2046)
|
||||
* Fix compatibility with GCC 4.8 (issue #2045)
|
||||
* Fix `cannot convert 'pgm_p' to 'const void*'` (issue #1707)
|
||||
|
||||
v7.0.2 (2024-01-19)
|
||||
------
|
||||
v6.19.1 (2022-01-14)
|
||||
-------
|
||||
|
||||
* Fix assertion `poolIndex < count_` after `JsonDocument::clear()` (issue #2034)
|
||||
* Fix crash when adding an object member in a too small `JsonDocument`
|
||||
* Fix filter not working in zero-copy mode (issue #1697)
|
||||
|
||||
v7.0.1 (2024-01-10)
|
||||
------
|
||||
v6.19.0 (2022-01-08)
|
||||
-------
|
||||
|
||||
* Fix "no matching function" with `JsonObjectConst::operator[]` (issue #2019)
|
||||
* Remove unused files in the PlatformIO package
|
||||
* Fix `volatile bool` serialized as `1` or `0` instead of `true` or `false` (issue #2029)
|
||||
* 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)
|
||||
|
||||
v7.0.0 (2024-01-03)
|
||||
------
|
||||
v6.18.5 (2021-09-28)
|
||||
-------
|
||||
|
||||
* Remove `BasicJsonDocument`
|
||||
* Remove `StaticJsonDocument`
|
||||
* Add abstract `Allocator` class
|
||||
* Merge `DynamicJsonDocument` with `JsonDocument`
|
||||
* Remove `JSON_ARRAY_SIZE()`, `JSON_OBJECT_SIZE()`, and `JSON_STRING_SIZE()`
|
||||
* Remove `ARDUINOJSON_ENABLE_STRING_DEDUPLICATION` (string deduplication cannot be disabled anymore)
|
||||
* Remove `JsonDocument::capacity()`
|
||||
* Store the strings in the heap
|
||||
* Reference-count shared strings
|
||||
* Always store `serialized("string")` by copy (#1915)
|
||||
* Remove the zero-copy mode of `deserializeJson()` and `deserializeMsgPack()`
|
||||
* Fix double lookup in `to<JsonVariant>()`
|
||||
* Fix double call to `size()` in `serializeMsgPack()`
|
||||
* Include `ARDUINOJSON_SLOT_OFFSET_SIZE` in the namespace name
|
||||
* Remove `JsonVariant::shallowCopy()`
|
||||
* `JsonDocument`'s capacity grows as needed, no need to pass it to the constructor anymore
|
||||
* `JsonDocument`'s allocator is not monotonic anymore, removed values get recycled
|
||||
* Show a link to the documentation when user passes an unsupported input type
|
||||
* Remove `JsonDocument::memoryUsage()`
|
||||
* Remove `JsonDocument::garbageCollect()`
|
||||
* Add `deserializeJson(JsonVariant, ...)` and `deserializeMsgPack(JsonVariant, ...)` (#1226)
|
||||
* Call `shrinkToFit()` in `deserializeJson()` and `deserializeMsgPack()`
|
||||
* `serializeJson()` and `serializeMsgPack()` replace the content of `std::string` and `String` instead of appending to it
|
||||
* Replace `add()` with `add<T>()` (`add(T)` is still supported)
|
||||
* Remove `createNestedArray()` and `createNestedObject()` (use `to<JsonArray>()` and `to<JsonObject>()` instead)
|
||||
* Set `ARDUINOJSON_EMBEDDED_MODE` to `1` on Nios II (issue #1657)
|
||||
|
||||
v6.18.4 (2021-09-06)
|
||||
-------
|
||||
|
||||
* Fixed error `'dummy' may be used uninitialized` on GCC 11
|
||||
* Fixed error `expected unqualified-id before 'const'` on GCC 11 (issue #1622)
|
||||
* Filter: exact match takes precedence over wildcard (issue #1628)
|
||||
* Fixed deserialization of `\u0000` (issue #1646)
|
||||
|
||||
v6.18.3 (2021-07-27)
|
||||
-------
|
||||
|
||||
* Changed return type of `convertToJson()` and `Converter<T>::toJson()` to `void`
|
||||
* Added `as<std::string_view>()` and `is<std::string_view>()`
|
||||
|
||||
v6.18.2 (2021-07-19)
|
||||
-------
|
||||
|
||||
* Removed a symlink because the Arduino Library Specification forbids it
|
||||
|
||||
v6.18.1 (2021-07-03)
|
||||
-------
|
||||
|
||||
* Fixed support for `volatile float` and `volatile double` (issue #1557)
|
||||
* Fixed error `[Pe070]: incomplete type is not allowed` on IAR (issue #1560)
|
||||
* Fixed `serializeJson(doc, String)` when allocation fails (issue #1572)
|
||||
* Fixed clang-tidy warnings (issue #1574, PR #1577 by @armandas)
|
||||
* Added fake class `InvalidConversion<T1,T2>` to easily identify invalid conversions (issue #1585)
|
||||
* Added support for `std::string_view` (issue #1578, PR #1554 by @0xFEEDC0DE64)
|
||||
* Fixed warning `definition of implicit copy constructor for 'MsgPackDeserializer' is deprecated because it has a user-declared copy assignment operator`
|
||||
* Added `JsonArray::clear()` (issue #1597)
|
||||
* Fixed `JsonVariant::as<unsigned>()` (issue #1601)
|
||||
* Added support for ESP-IDF component build (PR #1562 by @qt1, PR #1599 by @andreaskuster)
|
||||
|
||||
v6.18.0 (2021-05-05)
|
||||
-------
|
||||
|
||||
* Added support for custom converters (issue #687)
|
||||
* Added support for `Printable` (issue #1444)
|
||||
* Removed support for `char` values, see below (issue #1498)
|
||||
* `deserializeJson()` leaves `\uXXXX` unchanged instead of returning `NotSupported`
|
||||
* `deserializeMsgPack()` inserts `null` instead of returning `NotSupported`
|
||||
* Removed `DeserializationError::NotSupported`
|
||||
* Added `JsonVariant::is<JsonArrayConst/JsonObjectConst>()` (issue #1412)
|
||||
* Added `JsonVariant::is<JsonVariant/JsonVariantConst>()` (issue #1412)
|
||||
* Changed `JsonVariantConst::is<JsonArray/JsonObject>()` to return `false` (issue #1412)
|
||||
* Simplified `JsonVariant::as<T>()` to always return `T` (see below)
|
||||
* Updated folders list in `.mbedignore` (PR #1515 by @AGlass0fMilk)
|
||||
* Fixed member-call-on-null-pointer in `getMember()` when array is empty
|
||||
* `serializeMsgPack(doc, buffer, size)` doesn't add null-terminator anymore (issue #1545)
|
||||
* `serializeJson(doc, buffer, size)` adds null-terminator only if there is enough room
|
||||
* PlatformIO: set `build.libArchive` to `false` (PR #1550 by @askreet)
|
||||
|
||||
> ### BREAKING CHANGES
|
||||
>
|
||||
> As every major release, ArduinoJson 7 introduces several breaking changes.
|
||||
> I added some stubs so that most existing programs should compile, but I highty recommend you upgrade your code.
|
||||
> #### Support for `char` removed
|
||||
>
|
||||
> #### `JsonDocument`
|
||||
> We cannot cast a `JsonVariant` to a `char` anymore, so the following will break:
|
||||
> ```c++
|
||||
> char age = doc["age"]; // error: no matching function for call to 'variantAs(VariantData*&)'
|
||||
> ```
|
||||
> Instead, you must use another integral type, such as `int8_t`:
|
||||
> ```c++
|
||||
> int8_t age = doc["age"]; // OK
|
||||
> ```
|
||||
>
|
||||
> Similarly, we cannot assign from a `char` anymore, so the following will break:
|
||||
> ```c++
|
||||
> char age;
|
||||
> doc["age"] = age; // error: no matching function for call to 'VariantRef::set(const char&)'
|
||||
> ```
|
||||
> Instead, you must use another integral type, such as `int8_t`:
|
||||
> ```c++
|
||||
> int8_t age;
|
||||
> doc["age"] = age; // OK
|
||||
> ```
|
||||
> A deprecation warning with the message "Support for `char` is deprecated, use `int8_t` or `uint8_t` instead" was added to allow a smooth transition.
|
||||
>
|
||||
> #### `as<T>()` always returns `T`
|
||||
>
|
||||
> Previously, `JsonVariant::as<T>()` could return a type different from `T`.
|
||||
> The most common example is `as<char*>()` that returned a `const char*`.
|
||||
> While this feature simplified a few use cases, it was confusing and complicated the
|
||||
> implementation of custom converters.
|
||||
>
|
||||
> Starting from this version, `as<T>` doesn't try to auto-correct the return type and always return `T`,
|
||||
> which means that you cannot write this anymore:
|
||||
>
|
||||
> ```c++
|
||||
> Serial.println(doc["sensor"].as<char*>()); // error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
|
||||
> ```
|
||||
>
|
||||
> In ArduinoJson 6, you could allocate the memory pool on the stack (with `StaticJsonDocument`) or in the heap (with `DynamicJsonDocument`).
|
||||
> In ArduinoJson 7, the memory pool is always allocated in the heap, so `StaticJsonDocument` and `DynamicJsonDocument` have been merged into `JsonDocument`.
|
||||
>
|
||||
> In ArduinoJson 6, `JsonDocument` had a fixed capacity; in ArduinoJson 7, it has an elastic capacity that grows as needed.
|
||||
> Therefore, you don't need to specify the capacity anymore, so the macros `JSON_ARRAY_SIZE()`, `JSON_OBJECT_SIZE()`, and `JSON_STRING_SIZE()` have been removed.
|
||||
> Instead, you must write:
|
||||
>
|
||||
> ```c++
|
||||
> // ArduinoJson 6
|
||||
> StaticJsonDocument<256> doc;
|
||||
> // or
|
||||
> DynamicJsonDocument doc(256);
|
||||
> Serial.println(doc["sensor"].as<const char*>()); // OK
|
||||
> ```
|
||||
>
|
||||
> A deprecation warning with the message "Replace `as<char*>()` with `as<const char*>()`" was added to allow a smooth transition.
|
||||
>
|
||||
> #### `DeserializationError::NotSupported` removed
|
||||
>
|
||||
> On a different topic, `DeserializationError::NotSupported` has been removed.
|
||||
> Instead of returning this error:
|
||||
>
|
||||
> * `deserializeJson()` leaves `\uXXXX` unchanged (only when `ARDUINOJSON_DECODE_UNICODE` is `0`)
|
||||
> * `deserializeMsgPack()` replaces unsupported values with `null`s
|
||||
>
|
||||
> #### Const-aware `is<T>()`
|
||||
>
|
||||
> Lastly, a very minor change concerns `JsonVariantConst::is<T>()`.
|
||||
> It used to return `true` for `JsonArray` and `JsonOject`, but now it returns `false`.
|
||||
> Instead, you must use `JsonArrayConst` and `JsonObjectConst`.
|
||||
|
||||
v6.17.3 (2021-02-15)
|
||||
-------
|
||||
|
||||
* Made `JsonDocument`'s destructor protected (issue #1480)
|
||||
* Added missing calls to `client.stop()` in `JsonHttpClient.ino` (issue #1485)
|
||||
* Fixed error `expected ')' before 'char'` when `isdigit()` is a macro (issue #1487)
|
||||
* Fixed error `definition of implicit copy constructor is deprecated` on Clang 10
|
||||
* PlatformIO: set framework compatibility to `*` (PR #1490 by @maxgerhardt)
|
||||
|
||||
v6.17.2 (2020-11-14)
|
||||
-------
|
||||
|
||||
* Fixed invalid conversion error in `operator|(JsonVariant, char*)` (issue #1432)
|
||||
* Changed the default value of `ARDUINOJSON_ENABLE_PROGMEM` (issue #1433).
|
||||
It now checks that the `pgm_read_XXX` macros are defined before enabling `PROGMEM`.
|
||||
|
||||
v6.17.1 (2020-11-07)
|
||||
-------
|
||||
|
||||
* Fixed error `ambiguous overload for 'operator|'` (issue #1411)
|
||||
* Fixed `operator|(MemberProxy, JsonObject)` (issue #1415)
|
||||
* Allowed more than 32767 values in non-embedded mode (issue #1414)
|
||||
|
||||
v6.17.0 (2020-10-19)
|
||||
-------
|
||||
|
||||
* Added a build failure when nullptr is defined as a macro (issue #1355)
|
||||
* Added `JsonDocument::overflowed()` which tells if the memory pool was too small (issue #1358)
|
||||
* Added `DeserializationError::EmptyInput` which tells if the input was empty
|
||||
* Added `DeserializationError::f_str()` which returns a `const __FlashStringHelper*` (issue #846)
|
||||
* Added `operator|(JsonVariantConst, JsonVariantConst)`
|
||||
* Added filtering for MessagePack (issue #1298, PR #1394 by Luca Passarella)
|
||||
* Moved float convertion tables to PROGMEM
|
||||
* Fixed `JsonVariant::set((char*)0)` which returned false instead of true (issue #1368)
|
||||
* Fixed error `No such file or directory #include <WString.h>` (issue #1381)
|
||||
|
||||
v6.16.1 (2020-08-04)
|
||||
-------
|
||||
|
||||
* Fixed `deserializeJson()` that stopped reading after `{}` (issue #1335)
|
||||
|
||||
v6.16.0 (2020-08-01)
|
||||
-------
|
||||
|
||||
* Added comparisons (`>`, `>=`, `==`, `!=`, `<`, and `<=`) between `JsonVariant`s
|
||||
* Added string deduplication (issue #1303)
|
||||
* Added `JsonString::operator!=`
|
||||
* Added wildcard key (`*`) for filters (issue #1309)
|
||||
* Set `ARDUINOJSON_DECODE_UNICODE` to `1` by default
|
||||
* Fixed `copyArray()` not working with `String`, `ElementProxy`, and `MemberProxy`
|
||||
* Fixed error `getOrAddElement is not a member of ElementProxy` (issue #1311)
|
||||
* Fixed excessive stack usage when compiled with `-Og` (issues #1210 and #1314)
|
||||
* Fixed `Warning[Pa093]: implicit conversion from floating point to integer` on IAR compiler (PR #1328 by @stawiski)
|
||||
|
||||
v6.15.2 (2020-05-15)
|
||||
-------
|
||||
|
||||
* CMake: don't build tests when imported in another project
|
||||
* CMake: made project arch-independent
|
||||
* Visual Studio: fixed error C2766 with flag `/Zc:__cplusplus` (issue #1250)
|
||||
* Added support for `JsonDocument` to `copyArray()` (issue #1255)
|
||||
* Added support for `enum`s in `as<T>()` and `is<T>()` (issue #1256)
|
||||
* Added `JsonVariant` as an input type for `deserializeXxx()`
|
||||
For example, you can do: `deserializeJson(doc2, doc1["payload"])`
|
||||
* Break the build if using 64-bit integers with ARDUINOJSON_USE_LONG_LONG==0
|
||||
|
||||
v6.15.1 (2020-04-08)
|
||||
-------
|
||||
|
||||
* Fixed "maybe-uninitialized" warning (issue #1217)
|
||||
* Fixed "statement is unreachable" warning on IAR (issue #1233)
|
||||
* Fixed "pointless integer comparison" warning on IAR (issue #1233)
|
||||
* Added CMake "install" target (issue #1209)
|
||||
* Disabled alignment on AVR (issue #1231)
|
||||
|
||||
v6.15.0 (2020-03-22)
|
||||
-------
|
||||
|
||||
* Added `DeserializationOption::Filter` (issue #959)
|
||||
* Added example `JsonFilterExample.ino`
|
||||
* Changed the array subscript operator to automatically add missing elements
|
||||
* Fixed "deprecated-copy" warning on GCC 9 (fixes #1184)
|
||||
* Fixed `MemberProxy::set(char[])` not duplicating the string (issue #1191)
|
||||
* Fixed enums serialized as booleans (issue #1197)
|
||||
* Fixed incorrect string comparison on some platforms (issue #1198)
|
||||
* Added move-constructor and move-assignment to `BasicJsonDocument`
|
||||
* Added `BasicJsonDocument::garbageCollect()` (issue #1195)
|
||||
* Added `StaticJsonDocument::garbageCollect()`
|
||||
* Changed copy-constructor of `BasicJsonDocument` to preserve the capacity of the source.
|
||||
* Removed copy-constructor of `JsonDocument` (issue #1189)
|
||||
|
||||
> ### BREAKING CHANGES
|
||||
>
|
||||
> // ArduinoJson 7
|
||||
> JsonDocument doc;
|
||||
> #### Copy-constructor of `BasicJsonDocument`
|
||||
>
|
||||
> In previous versions, the copy constructor of `BasicJsonDocument` looked at the source's `memoryUsage()` to choose its capacity.
|
||||
> Now, the copy constructor of `BasicJsonDocument` uses the same capacity as the source.
|
||||
>
|
||||
> Example:
|
||||
>
|
||||
> ```c++
|
||||
> DynamicJsonDocument doc1(64);
|
||||
> doc1.set(String("example"));
|
||||
>
|
||||
> DynamicJsonDocument doc2 = doc1;
|
||||
> Serial.print(doc2.capacity()); // 8 with ArduinoJson 6.14
|
||||
> // 64 with ArduinoJson 6.15
|
||||
> ```
|
||||
>
|
||||
> In ArduinoJson 7, `JsonDocument` reuses released memory, so `garbageCollect()` has been removed.
|
||||
> `shrinkToFit()` is still available and releases the over-allocated memory.
|
||||
> I made this change to get consistent results between copy-constructor and move-constructor, and whether RVO applies or not.
|
||||
>
|
||||
> Due to a change in the implementation, it's not possible to store a pointer to a variant from another `JsonDocument`, so `shallowCopy()` has been removed.
|
||||
> If you use the copy-constructor to optimize your documents, you can use `garbageCollect()` or `shrinkToFit()` instead.
|
||||
>
|
||||
> #### Copy-constructor of `JsonDocument`
|
||||
>
|
||||
> In previous versions, it was possible to create a function that take a `JsonDocument` by value.
|
||||
>
|
||||
> ```c++
|
||||
> void myFunction(JsonDocument doc) {}
|
||||
> ```
|
||||
>
|
||||
> This function gives the wrong clues because it doesn't receive a copy of the `JsonDocument`, only a sliced version.
|
||||
> It worked because the copy constructor copied the internal pointers, but it was an accident.
|
||||
>
|
||||
> From now, if you need to pass a `JsonDocument` to a function, you must use a reference:
|
||||
>
|
||||
> ```c++
|
||||
> void myFunction(JsonDocument& doc) {}
|
||||
> ```
|
||||
|
||||
v6.14.1 (2020-01-27)
|
||||
-------
|
||||
|
||||
* Fixed regression in UTF16 decoding (issue #1173)
|
||||
* Fixed `containsKey()` on `JsonVariantConst`
|
||||
* Added `getElement()` and `getMember()` to `JsonVariantConst`
|
||||
|
||||
v6.14.0 (2020-01-16)
|
||||
-------
|
||||
|
||||
* Added `BasicJsonDocument::shrinkToFit()`
|
||||
* Added support of `uint8_t` for `serializeJson()`, `serializeJsonPretty()`, and `serializeMsgPack()` (issue #1142)
|
||||
* Added `ARDUINOJSON_ENABLE_COMMENTS` to enable support for comments (defaults to 0)
|
||||
* Auto enable support for `std::string` and `std::stream` on modern compilers (issue #1156)
|
||||
(No need to define `ARDUINOJSON_ENABLE_STD_STRING` and `ARDUINOJSON_ENABLE_STD_STREAM` anymore)
|
||||
* Improved decoding of UTF-16 surrogate pairs (PR #1157 by @kaysievers)
|
||||
(ArduinoJson now produces standard UTF-8 instead of CESU-8)
|
||||
* Added `measureJson`, `measureJsonPretty`, and `measureMsgPack` to `keywords.txt`
|
||||
(This file is used for syntax highlighting in the Arduino IDE)
|
||||
* Fixed `variant.is<nullptr_t>()`
|
||||
* Fixed value returned by `serializeJson()`, `serializeJsonPretty()`, and `serializeMsgPack()` when writing to a `String`
|
||||
* Improved speed of `serializeJson()`, `serializeJsonPretty()`, and `serializeMsgPack()` when writing to a `String`
|
||||
|
||||
> ### BREAKING CHANGES
|
||||
>
|
||||
> In ArduinoJson 6, the meaning of `memoryUsage()` was clear: it returned the number of bytes used in the memory pool.
|
||||
> In ArduinoJson 7, the meaning of `memoryUsage()` would be ambiguous, so it has been removed.
|
||||
> #### Comments
|
||||
>
|
||||
> Support for comments in input is now optional and disabled by default.
|
||||
>
|
||||
> #### Custom allocators
|
||||
>
|
||||
> In ArduinoJson 6, you could specify a custom allocator class as a template parameter of `BasicJsonDocument`.
|
||||
> In ArduinoJson 7, you must inherit from `ArduinoJson::Allocator` and pass a pointer to an instance of your class to the constructor of `JsonDocument`.
|
||||
> If you need support for comments, you must defined `ARDUINOJSON_ENABLE_COMMENTS` to `1`; otherwise, you'll receive `InvalidInput` errors.
|
||||
>
|
||||
> ```c++
|
||||
> // ArduinoJson 6
|
||||
> class MyAllocator {
|
||||
> // ...
|
||||
> };
|
||||
> BasicJsonDocument<MyAllocator> doc(256);
|
||||
>
|
||||
> // ArduinoJson 7
|
||||
> class MyAllocator : public ArduinoJson::Allocator {
|
||||
> // ...
|
||||
> };
|
||||
> MyAllocator myAllocator;
|
||||
> JsonDocument doc(&myAllocator);
|
||||
> #define ARDUINOJSON_ENABLE_COMMENTS 1
|
||||
> #include <ArduinoJson.h>
|
||||
> ```
|
||||
|
||||
v6.13.0 (2019-11-01)
|
||||
-------
|
||||
|
||||
* Added support for custom writer/reader classes (issue #1088)
|
||||
* Added conversion from `JsonArray` and `JsonObject` to `bool`, to be consistent with `JsonVariant`
|
||||
* Fixed `deserializeJson()` when input contains duplicate keys (issue #1095)
|
||||
* Improved `deserializeMsgPack()` speed by reading several bytes at once
|
||||
* Added detection of Atmel AVR8/GNU C Compiler (issue #1112)
|
||||
* Fixed deserializer that stopped reading at the first `0xFF` (PR #1118 by @mikee47)
|
||||
* Fixed dangling reference in copies of `MemberProxy` and `ElementProxy` (issue #1120)
|
||||
|
||||
v6.12.0 (2019-09-05)
|
||||
-------
|
||||
|
||||
* Use absolute instead of relative includes (issue #1072)
|
||||
* Changed `JsonVariant::as<bool>()` to return `true` for any non-null value (issue #1005)
|
||||
* Moved ancillary files to `extras/` (issue #1011)
|
||||
|
||||
v6.11.5 (2019-08-23)
|
||||
-------
|
||||
|
||||
* Added fallback implementations of `strlen_P()`, `strncmp_P()`, `strcmp_P()`, and `memcpy_P()` (issue #1073)
|
||||
|
||||
v6.11.4 (2019-08-12)
|
||||
-------
|
||||
|
||||
* Added `measureJson()` to the `ArduinoJson` namespace (PR #1069 by @nomis)
|
||||
* Added support for `basic_string<char, traits, allocator>` (issue #1045)
|
||||
* Fixed example `JsonConfigFile.ino` for ESP8266
|
||||
* Include `Arduino.h` if `ARDUINO` is defined (PR #1071 by @nomis)
|
||||
|
||||
v6.11.3 (2019-07-22)
|
||||
-------
|
||||
|
||||
* Added operators `==` and `!=` for `JsonDocument`, `ElementProxy`, and `MemberProxy`
|
||||
* Fixed comparison of `JsonVariant` when one contains a linked string and the other contains an owned string (issue #1051)
|
||||
|
||||
v6.11.2 (2019-07-08)
|
||||
-------
|
||||
|
||||
* Fixed assignment of `JsonDocument` to `JsonVariant` (issue #1023)
|
||||
* Fix invalid conversion error on Particle Argon (issue #1035)
|
||||
|
||||
v6.11.1 (2019-06-21)
|
||||
-------
|
||||
|
||||
* Fixed `serialized()` not working with Flash strings (issue #1030)
|
||||
|
||||
v6.11.0 (2019-05-26)
|
||||
-------
|
||||
|
||||
* Fixed `deserializeJson()` silently accepting a `Stream*` (issue #978)
|
||||
* Fixed invalid result from `operator|` (issue #981)
|
||||
* Made `deserializeJson()` more picky about trailing characters (issue #980)
|
||||
* Added `ARDUINOJSON_ENABLE_NAN` (default=0) to enable NaN in JSON (issue #973)
|
||||
* Added `ARDUINOJSON_ENABLE_INFINITY` (default=0) to enable Infinity in JSON
|
||||
* Removed implicit conversion in comparison operators (issue #998)
|
||||
* Added lexicographical comparison for `JsonVariant`
|
||||
* Added support for `nullptr` (issue #998)
|
||||
|
||||
> ### BREAKING CHANGES
|
||||
>
|
||||
> #### NaN and Infinity
|
||||
>
|
||||
> The JSON specification allows neither NaN not Infinity, but previous
|
||||
> versions of ArduinoJson supported it. Now, ArduinoJson behaves like most
|
||||
> other libraries: a NaN or and Infinity in the `JsonDocument`, becomes
|
||||
> a `null` in the output JSON. Also, `deserializeJson()` returns
|
||||
> `InvalidInput` if the JSON document contains NaN or Infinity.
|
||||
>
|
||||
> This version still supports NaN and Infinity in JSON documents, but
|
||||
> it's disabled by default to be compatible with other JSON parsers.
|
||||
> If you need the old behavior back, define `ARDUINOJSON_ENABLE_NAN` and
|
||||
> `ARDUINOJSON_ENABLE_INFINITY` to `1`;:
|
||||
>
|
||||
> ```c++
|
||||
> #define ARDUINOJSON_ENABLE_NAN 1
|
||||
> #define ARDUINOJSON_ENABLE_INFINITY 1
|
||||
> #include <ArduinoJson.h>
|
||||
> ```
|
||||
>
|
||||
> #### The "or" operator
|
||||
>
|
||||
> This version slightly changes the behavior of the | operator when the
|
||||
> variant contains a float and the user requests an integer.
|
||||
>
|
||||
> #### `createNestedArray()` and `createNestedObject()`
|
||||
> Older versions returned the floating point value truncated.
|
||||
> Now, it returns the default value.
|
||||
>
|
||||
> ```c++
|
||||
> // suppose variant contains 1.2
|
||||
> int value = variant | 3;
|
||||
>
|
||||
> // old behavior:
|
||||
> value == 1
|
||||
>
|
||||
> // new behavior
|
||||
> value == 3
|
||||
> ```
|
||||
>
|
||||
> If you need the old behavior, you must add `if (variant.is<float>())`.
|
||||
|
||||
v6.10.1 (2019-04-23)
|
||||
-------
|
||||
|
||||
* Fixed error "attributes are not allowed on a function-definition"
|
||||
* Fixed `deserializeJson()` not being picky enough (issue #969)
|
||||
* Fixed error "no matching function for call to write(uint8_t)" (issue #972)
|
||||
|
||||
v6.10.0 (2019-03-22)
|
||||
-------
|
||||
|
||||
* Fixed an integer overflow in the JSON deserializer
|
||||
* Added overflow handling in `JsonVariant::as<T>()` and `JsonVariant::is<T>()`.
|
||||
- `as<T>()` returns `0` if the integer `T` overflows
|
||||
- `is<T>()` returns `false` if the integer `T` overflows
|
||||
* Added `BasicJsonDocument` to support custom allocator (issue #876)
|
||||
* Added `JsonDocument::containsKey()` (issue #938)
|
||||
* Added `JsonVariant::containsKey()`
|
||||
|
||||
v6.9.1 (2019-03-01)
|
||||
------
|
||||
|
||||
* Fixed warning "unused variable" with GCC 4.4 (issue #912)
|
||||
* Fixed warning "cast increases required alignment" (issue #914)
|
||||
* Fixed warning "conversion may alter value" (issue #914)
|
||||
* Fixed naming conflict with "CAPACITY" (issue #839)
|
||||
* Muted warning "will change in GCC 7.1" (issue #914)
|
||||
* Added a clear error message for `StaticJsonBuffer` and `DynamicJsonBuffer`
|
||||
* Marked ArduinoJson.h as a "system header"
|
||||
|
||||
v6.9.0 (2019-02-26)
|
||||
------
|
||||
|
||||
* Decode escaped Unicode characters like \u00DE (issue #304, PR #791)
|
||||
Many thanks to Daniel Schulte (aka @trilader) who implemented this feature.
|
||||
* Added option ARDUINOJSON_DECODE_UNICODE to enable it
|
||||
* Converted `JsonArray::copyFrom()/copyTo()` to free functions `copyArray()`
|
||||
* Renamed `JsonArray::copyFrom()` and `JsonObject::copyFrom()` to `set()`
|
||||
* Renamed `JsonArray::get()` to `getElement()`
|
||||
* Renamed `JsonArray::add()` (without arg) to `addElement()`
|
||||
* Renamed `JsonObject::get()` to `getMember()`
|
||||
* Renamed `JsonObject::getOrCreate()` to `getOrAddMember()`
|
||||
* Fixed `JsonVariant::isNull()` not returning `true` after `set((char*)0)`
|
||||
* Fixed segfault after `variant.set(serialized((char*)0))`
|
||||
* Detect `IncompleteInput` in `false`, `true`, and `null`
|
||||
* Added `JsonDocument::size()`
|
||||
* Added `JsonDocument::remove()`
|
||||
* Added `JsonVariant::clear()`
|
||||
* Added `JsonVariant::remove()`
|
||||
|
||||
v6.8.0-beta (2019-01-30)
|
||||
-----------
|
||||
|
||||
* Import functions in the ArduinoJson namespace to get clearer errors
|
||||
* Improved syntax highlighting in Arduino IDE
|
||||
* Removed default capacity of `DynamicJsonDocument`
|
||||
* `JsonArray::copyFrom()` accepts `JsonArrayConst`
|
||||
* `JsonVariant::set()` accepts `JsonArrayConst` and `JsonObjectConst`
|
||||
* `JsonDocument` was missing in the ArduinoJson namespace
|
||||
* Added `memoryUsage()` to `JsonArray`, `JsonObject`, and `JsonVariant`
|
||||
* Added `nesting()` to `JsonArray`, `JsonDocument`, `JsonObject`, and `JsonVariant`
|
||||
* Replaced `JsonDocument::nestingLimit` with an additional parameter
|
||||
to `deserializeJson()` and `deserializeMsgPack()`
|
||||
* Fixed uninitialized variant in `JsonDocument`
|
||||
* Fixed `StaticJsonDocument` copy constructor and copy assignment
|
||||
* The copy constructor of `DynamicJsonDocument` chooses the capacity according to the memory usage of the source, not from the capacity of the source.
|
||||
* Added the ability to create/assign a `StaticJsonDocument`/`DynamicJsonDocument` from a `JsonArray`/`JsonObject`/`JsonVariant`
|
||||
* Added `JsonDocument::isNull()`
|
||||
* Added `JsonDocument::operator[]`
|
||||
* Added `ARDUINOJSON_TAB` to configure the indentation character
|
||||
* Reduced the size of the pretty JSON serializer
|
||||
* Added `add()`, `createNestedArray()` and `createNestedObject()` to `JsonVariant`
|
||||
* `JsonVariant` automatically promotes to `JsonObject` or `JsonArray` on write.
|
||||
Calling `JsonVariant::to<T>()` is not required anymore.
|
||||
* `JsonDocument` now support the same operations as `JsonVariant`.
|
||||
Calling `JsonDocument::as<T>()` is not required anymore.
|
||||
* Fixed example `JsonHttpClient.ino`
|
||||
* User can now use a `JsonString` as a key or a value
|
||||
|
||||
> ### BREAKING CHANGES
|
||||
>
|
||||
> #### `DynamicJsonDocument`'s constructor
|
||||
>
|
||||
> The parameter to the constructor of `DynamicJsonDocument` is now mandatory
|
||||
>
|
||||
> In ArduinoJson 6, you could create a nested array or object with `createNestedArray()` and `createNestedObject()`.
|
||||
> In ArduinoJson 7, you must use `add<T>()` or `to<T>()` instead.
|
||||
>
|
||||
> For example, to create `[[],{}]`, you would write:
|
||||
> Old code:
|
||||
>
|
||||
> ```c++
|
||||
> // ArduinoJson 6
|
||||
> arr.createNestedArray();
|
||||
> arr.createNestedObject();
|
||||
>
|
||||
> // ArduinoJson 7
|
||||
> arr.add<JsonArray>();
|
||||
> arr.add<JsonObject>();
|
||||
> DynamicJsonDocument doc;
|
||||
> ```
|
||||
>
|
||||
> And to create `{"array":[],"object":{}}`, you would write:
|
||||
> New code:
|
||||
>
|
||||
> ```c++
|
||||
> // ArduinoJson 6
|
||||
> obj.createNestedArray("array");
|
||||
> obj.createNestedObject("object");
|
||||
>
|
||||
> // ArduinoJson 7
|
||||
> obj["array"].to<JsonArray>();
|
||||
> obj["object"].to<JsonObject>();
|
||||
> DynamicJsonDocument doc(1024);
|
||||
> ```
|
||||
>
|
||||
> #### Nesting limit
|
||||
>
|
||||
> `JsonDocument::nestingLimit` was replaced with a new parameter to `deserializeJson()` and `deserializeMsgPack()`.
|
||||
>
|
||||
> Old code:
|
||||
>
|
||||
> ```c++
|
||||
> doc.nestingLimit = 15;
|
||||
> deserializeJson(doc, input);
|
||||
> ```
|
||||
>
|
||||
> New code:
|
||||
>
|
||||
> ```c++
|
||||
> deserializeJson(doc, input, DeserializationOption::NestingLimit(15));
|
||||
> ```
|
||||
|
||||
v6.7.0-beta (2018-12-07)
|
||||
-----------
|
||||
|
||||
* Removed the automatic expansion of `DynamicJsonDocument`, it now has a fixed capacity.
|
||||
* Restored the monotonic allocator because the code was getting too big
|
||||
* Reduced the memory usage
|
||||
* Reduced the code size
|
||||
* Renamed `JsonKey` to `JsonString`
|
||||
* Removed spurious files in the Particle library
|
||||
|
||||
v6.6.0-beta (2018-11-13)
|
||||
-----------
|
||||
|
||||
* Removed `JsonArray::is<T>(i)` and `JsonArray::set(i,v)`
|
||||
* Removed `JsonObject::is<T>(k)` and `JsonObject::set(k,v)`
|
||||
* Replaced `T JsonArray::get<T>(i)` with `JsonVariant JsonArray::get(i)`
|
||||
* Replaced `T JsonObject::get<T>(k)` with `JsonVariant JsonObject::get(k)`
|
||||
* Added `JSON_STRING_SIZE()`
|
||||
* ~~Replacing or removing a value now releases the memory~~
|
||||
* Added `DeserializationError::code()` to be used in switch statements (issue #846)
|
||||
|
||||
v6.5.0-beta (2018-10-13)
|
||||
-----------
|
||||
|
||||
* Added implicit conversion from `JsonArray` and `JsonObject` to `JsonVariant`
|
||||
* Allow mixed configuration in compilation units (issue #809)
|
||||
* Fixed object keys not being duplicated
|
||||
* `JsonPair::key()` now returns a `JsonKey`
|
||||
* Increased the default capacity of `DynamicJsonDocument`
|
||||
* Fixed `JsonVariant::is<String>()` (closes #763)
|
||||
* Added `JsonArrayConst`, `JsonObjectConst`, and `JsonVariantConst`
|
||||
* Added copy-constructor and copy-assignment-operator for `JsonDocument` (issue #827)
|
||||
|
||||
v6.4.0-beta (2018-09-11)
|
||||
-----------
|
||||
|
||||
* Copy `JsonArray` and `JsonObject`, instead of storing pointers (issue #780)
|
||||
* Added `JsonVariant::to<JsonArray>()` and `JsonVariant::to<JsonObject>()`
|
||||
|
||||
v6.3.0-beta (2018-08-31)
|
||||
-----------
|
||||
|
||||
* Implemented reference semantics for `JsonVariant`
|
||||
* Replaced `JsonPair`'s `key` and `value` with `key()` and `value()`
|
||||
* Fixed `serializeJson(obj[key], dst)` (issue #794)
|
||||
|
||||
> ### BREAKING CHANGES
|
||||
>
|
||||
> #### JsonVariant
|
||||
>
|
||||
> `JsonVariant` now has a semantic similar to `JsonObject` and `JsonArray`.
|
||||
> It's a reference to a value stored in the `JsonDocument`.
|
||||
> As a consequence, a `JsonVariant` cannot be used as a standalone variable anymore.
|
||||
>
|
||||
> Old code:
|
||||
>
|
||||
> ```c++
|
||||
> JsonVariant myValue = 42;
|
||||
> ```
|
||||
>
|
||||
> New code:
|
||||
>
|
||||
> ```c++
|
||||
> DynamicJsonDocument doc;
|
||||
> JsonVariant myValue = doc.to<JsonVariant>();
|
||||
> myValue.set(42);
|
||||
> ```
|
||||
>
|
||||
> #### JsonPair
|
||||
>
|
||||
> Old code:
|
||||
>
|
||||
> ```c++
|
||||
> for(JsonPair p : myObject) {
|
||||
> Serial.println(p.key);
|
||||
> Serial.println(p.value.as<int>());
|
||||
> }
|
||||
> ```
|
||||
>
|
||||
> New code:
|
||||
>
|
||||
> ```c++
|
||||
> for(JsonPair p : myObject) {
|
||||
> Serial.println(p.key());
|
||||
> Serial.println(p.value().as<int>());
|
||||
> }
|
||||
> ```
|
||||
>
|
||||
> CAUTION: the key is now read only!
|
||||
|
||||
v6.2.3-beta (2018-07-19)
|
||||
-----------
|
||||
|
||||
* Fixed exception when using Flash strings as object keys (issue #784)
|
||||
|
||||
v6.2.2-beta (2018-07-18)
|
||||
-----------
|
||||
|
||||
* Fixed `invalid application of 'sizeof' to incomplete type '__FlashStringHelper'` (issue #783)
|
||||
* Fixed `char[]` not duplicated when passed to `JsonVariant::operator[]`
|
||||
|
||||
v6.2.1-beta (2018-07-17)
|
||||
-----------
|
||||
|
||||
* Fixed `JsonObject` not inserting keys of type `String` (issue #782)
|
||||
|
||||
v6.2.0-beta (2018-07-12)
|
||||
-----------
|
||||
|
||||
* Disabled lazy number deserialization (issue #772)
|
||||
* Fixed `JsonVariant::is<int>()` that returned true for empty strings
|
||||
* Improved float serialization when `-fsingle-precision-constant` is used
|
||||
* Renamed function `RawJson()` to `serialized()`
|
||||
* `serializeMsgPack()` now supports values marked with `serialized()`
|
||||
|
||||
> ### BREAKING CHANGES
|
||||
>
|
||||
> #### Non quoted strings
|
||||
>
|
||||
> Non quoted strings are now forbidden in values, but they are still allowed in keys.
|
||||
> For example, `{key:"value"}` is accepted, but `{key:value}` is not.
|
||||
>
|
||||
> #### Preformatted values
|
||||
>
|
||||
> Old code:
|
||||
>
|
||||
> ```c++
|
||||
> object["values"] = RawJson("[1,2,3,4]");
|
||||
> ```
|
||||
>
|
||||
> New code:
|
||||
>
|
||||
> ```c++
|
||||
> object["values"] = serialized("[1,2,3,4]");
|
||||
> ```
|
||||
|
||||
v6.1.0-beta (2018-07-02)
|
||||
-----------
|
||||
|
||||
* Return `JsonArray` and `JsonObject` by value instead of reference (issue #309)
|
||||
* Replaced `success()` with `isNull()`
|
||||
|
||||
> ### BREAKING CHANGES
|
||||
>
|
||||
> Old code:
|
||||
>
|
||||
> ```c++
|
||||
> JsonObject& obj = doc.to<JsonObject>();
|
||||
> JsonArray& arr = obj.createNestedArray("key");
|
||||
> if (!arr.success()) {
|
||||
> Serial.println("Not enough memory");
|
||||
> return;
|
||||
> }
|
||||
> ```
|
||||
>
|
||||
> New code:
|
||||
>
|
||||
> ```c++
|
||||
> JsonObject obj = doc.to<JsonObject>();
|
||||
> JsonArray arr = obj.createNestedArray("key");
|
||||
> if (arr.isNull()) {
|
||||
> Serial.println("Not enough memory");
|
||||
> return;
|
||||
> }
|
||||
> ```
|
||||
|
||||
v6.0.1-beta (2018-06-11)
|
||||
-----------
|
||||
|
||||
* Fixed conflicts with `isnan()` and `isinf()` macros (issue #752)
|
||||
|
||||
v6.0.0-beta (2018-06-07)
|
||||
-----------
|
||||
|
||||
* Added `DynamicJsonDocument` and `StaticJsonDocument`
|
||||
* Added `deserializeJson()`
|
||||
* Added `serializeJson()` and `serializeJsonPretty()`
|
||||
* Added `measureJson()` and `measureJsonPretty()`
|
||||
* Added `serializeMsgPack()`, `deserializeMsgPack()` and `measureMsgPack()` (issue #358)
|
||||
* Added example `MsgPackParser.ino` (issue #358)
|
||||
* Added support for non zero-terminated strings (issue #704)
|
||||
* Removed `JsonBuffer::parseArray()`, `parseObject()` and `parse()`
|
||||
* Removed `JsonBuffer::createArray()` and `createObject()`
|
||||
* Removed `printTo()` and `prettyPrintTo()`
|
||||
* Removed `measureLength()` and `measurePrettyLength()`
|
||||
* Removed all deprecated features
|
||||
|
||||
> ### BREAKING CHANGES
|
||||
>
|
||||
> #### Deserialization
|
||||
>
|
||||
> Old code:
|
||||
>
|
||||
> ```c++
|
||||
> DynamicJsonBuffer jb;
|
||||
> JsonObject& obj = jb.parseObject(json);
|
||||
> if (obj.success()) {
|
||||
>
|
||||
> }
|
||||
> ```
|
||||
>
|
||||
> New code:
|
||||
>
|
||||
> ```c++
|
||||
> DynamicJsonDocument doc;
|
||||
> DeserializationError error = deserializeJson(doc, json);
|
||||
> if (error) {
|
||||
>
|
||||
> }
|
||||
> JsonObject& obj = doc.as<JsonObject>();
|
||||
> ```
|
||||
>
|
||||
> #### Serialization
|
||||
>
|
||||
> Old code:
|
||||
>
|
||||
> ```c++
|
||||
> DynamicJsonBuffer jb;
|
||||
> JsonObject& obj = jb.createObject();
|
||||
> obj["key"] = "value";
|
||||
> obj.printTo(Serial);
|
||||
> ```
|
||||
>
|
||||
> New code:
|
||||
>
|
||||
> ```c++
|
||||
> DynamicJsonDocument obj;
|
||||
> JsonObject& obj = doc.to<JsonObject>();
|
||||
> obj["key"] = "value";
|
||||
> serializeJson(doc, Serial);
|
||||
> ```
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ArduinoJson - https://arduinojson.org
|
||||
# Copyright © 2014-2024, Benoit BLANCHON
|
||||
# Copyright © 2014-2023, Benoit BLANCHON
|
||||
# MIT License
|
||||
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
@ -10,7 +10,7 @@ if(ESP_PLATFORM)
|
||||
return()
|
||||
endif()
|
||||
|
||||
project(ArduinoJson VERSION 7.2.0)
|
||||
project(ArduinoJson VERSION 6.21.2)
|
||||
|
||||
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||
include(CTest)
|
||||
|
@ -1,7 +1,7 @@
|
||||
The MIT License (MIT)
|
||||
---------------------
|
||||
|
||||
Copyright © 2014-2024, Benoit BLANCHON
|
||||
Copyright © 2014-2023, 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:
|
||||
|
||||
|
79
README.md
79
README.md
@ -4,10 +4,13 @@
|
||||
|
||||
---
|
||||
|
||||
[](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A7.x)
|
||||
[](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/7.x)
|
||||
[](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A6.x)
|
||||
[](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
|
||||
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:arduinojson)
|
||||
[](https://coveralls.io/github/bblanchon/ArduinoJson?branch=7.x)
|
||||
[](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
|
||||
[](https://www.ardu-badge.com/ArduinoJson/6.21.2)
|
||||
[](https://registry.platformio.org/packages/libraries/bblanchon/ArduinoJson?version=6.21.2)
|
||||
[](https://components.espressif.com/components/bblanchon/arduinojson)
|
||||
[](https://github.com/bblanchon/ArduinoJson/stargazers)
|
||||
[](https://github.com/sponsors/bblanchon)
|
||||
|
||||
@ -15,28 +18,31 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
|
||||
|
||||
## Features
|
||||
|
||||
* [JSON deserialization](https://arduinojson.org/v7/api/json/deserializejson/)
|
||||
* [Optionally decodes UTF-16 escape sequences to UTF-8](https://arduinojson.org/v7/api/config/decode_unicode/)
|
||||
* [Optionally supports comments in the input](https://arduinojson.org/v7/api/config/enable_comments/)
|
||||
* [Optionally filters the input to keep only desired values](https://arduinojson.org/v7/api/json/deserializejson/#filtering)
|
||||
* [JSON deserialization](https://arduinojson.org/v6/api/json/deserializejson/)
|
||||
* [Optionally decodes UTF-16 escape sequences to UTF-8](https://arduinojson.org/v6/api/config/decode_unicode/)
|
||||
* [Optionally stores links to the input buffer (zero-copy)](https://arduinojson.org/v6/api/json/deserializejson/)
|
||||
* [Optionally supports comments in the input](https://arduinojson.org/v6/api/config/enable_comments/)
|
||||
* [Optionally filters the input to keep only desired values](https://arduinojson.org/v6/api/json/deserializejson/#filtering)
|
||||
* Supports single quotes as a string delimiter
|
||||
* Compatible with [NDJSON](http://ndjson.org/) and [JSON Lines](https://jsonlines.org/)
|
||||
* [JSON serialization](https://arduinojson.org/v7/api/json/serializejson/)
|
||||
* [Can write to a buffer or a stream](https://arduinojson.org/v7/api/json/serializejson/)
|
||||
* [Optionally indents the document (prettified JSON)](https://arduinojson.org/v7/api/json/serializejsonpretty/)
|
||||
* [MessagePack serialization](https://arduinojson.org/v7/api/msgpack/serializemsgpack/)
|
||||
* [MessagePack deserialization](https://arduinojson.org/v7/api/msgpack/deserializemsgpack/)
|
||||
* [JSON serialization](https://arduinojson.org/v6/api/json/serializejson/)
|
||||
* [Can write to a buffer or a stream](https://arduinojson.org/v6/api/json/serializejson/)
|
||||
* [Optionally indents the document (prettified JSON)](https://arduinojson.org/v6/api/json/serializejsonpretty/)
|
||||
* [MessagePack serialization](https://arduinojson.org/v6/api/msgpack/serializemsgpack/)
|
||||
* [MessagePack deserialization](https://arduinojson.org/v6/api/msgpack/deserializemsgpack/)
|
||||
* Efficient
|
||||
* [Twice smaller than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/)
|
||||
* [Almost 10% faster than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/)
|
||||
* [Consumes roughly 10% less RAM than the "official" Arduino_JSON library](https://arduinojson.org/2019/11/19/arduinojson-vs-arduino_json/)
|
||||
* [Fixed memory allocation, no heap fragmentation](https://arduinojson.org/v6/api/jsondocument/)
|
||||
* [Optionally works without heap memory (zero malloc)](https://arduinojson.org/v6/api/staticjsondocument/)
|
||||
* [Deduplicates strings](https://arduinojson.org/news/2020/08/01/version-6-16-0/)
|
||||
* Versatile
|
||||
* Supports [custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v7/how-to/use-external-ram-on-esp32/)
|
||||
* Supports [`String`](https://arduinojson.org/v7/api/config/enable_arduino_string/), [`std::string`](https://arduinojson.org/v7/api/config/enable_std_string/), and [`std::string_view`](https://arduinojson.org/v7/api/config/enable_string_view/)
|
||||
* Supports [`Stream`](https://arduinojson.org/v7/api/config/enable_arduino_stream/) and [`std::istream`/`std::ostream`](https://arduinojson.org/v7/api/config/enable_std_stream/)
|
||||
* Supports [Flash strings](https://arduinojson.org/v7/api/config/enable_progmem/)
|
||||
* Supports [custom readers](https://arduinojson.org/v7/api/json/deserializejson/#custom-reader) and [custom writers](https://arduinojson.org/v7/api/json/serializejson/#custom-writer)
|
||||
* Supports [custom allocators (to use external RAM chip, for example)](https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/)
|
||||
* Supports [`String`](https://arduinojson.org/v6/api/config/enable_arduino_string/), [`std::string`](https://arduinojson.org/v6/api/config/enable_std_string/), and [`std::string_view`](https://arduinojson.org/v6/api/config/enable_string_view/)
|
||||
* Supports [`Stream`](https://arduinojson.org/v6/api/config/enable_arduino_stream/) and [`std::istream`/`std::ostream`](https://arduinojson.org/v6/api/config/enable_std_stream/)
|
||||
* Supports [Flash strings](https://arduinojson.org/v6/api/config/enable_progmem/)
|
||||
* Supports [custom readers](https://arduinojson.org/v6/api/json/deserializejson/#custom-reader) and [custom writers](https://arduinojson.org/v6/api/json/serializejson/#custom-writer)
|
||||
* Supports [custom converters](https://arduinojson.org/news/2021/05/04/version-6-18-0/)
|
||||
* Portable
|
||||
* Usable on any C++ project (not limited to Arduino)
|
||||
@ -66,29 +72,29 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
|
||||
* [Visual Micro](http://www.visualmicro.com/)
|
||||
* [Visual Studio](https://www.visualstudio.com/)
|
||||
* [Even works with online compilers like wandbox.org](https://wandbox.org/permlink/RlZSKy17DjJ6HcdN)
|
||||
* [CMake friendly](https://arduinojson.org/v7/how-to/use-arduinojson-with-cmake/)
|
||||
* [CMake friendly](https://arduinojson.org/v6/how-to/use-arduinojson-with-cmake/)
|
||||
* Well designed
|
||||
* [Elegant API](http://arduinojson.org/v7/example/)
|
||||
* [Elegant API](http://arduinojson.org/v6/example/)
|
||||
* [Thread-safe](https://en.wikipedia.org/wiki/Thread_safety)
|
||||
* Self-contained (no external dependency)
|
||||
* `const` friendly
|
||||
* [`for` friendly](https://arduinojson.org/v7/api/jsonobject/begin_end/)
|
||||
* [`for` friendly](https://arduinojson.org/v6/api/jsonobject/begin_end/)
|
||||
* [TMP friendly](https://en.wikipedia.org/wiki/Template_metaprogramming)
|
||||
* Handles [integer overflows](https://arduinojson.org/v7/api/jsonvariant/as/#integer-overflows)
|
||||
* Handles [integer overflows](https://arduinojson.org/v6/api/jsonvariant/as/#integer-overflows)
|
||||
* Well tested
|
||||
* [Unit test coverage close to 100%](https://coveralls.io/github/bblanchon/ArduinoJson?branch=7.x)
|
||||
* [Unit test coverage close to 100%](https://coveralls.io/github/bblanchon/ArduinoJson?branch=6.x)
|
||||
* Continuously tested on
|
||||
* [Visual Studio 2017, 2019, 2022](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/7.x)
|
||||
* [GCC 4.8, 5, 6, 7, 8, 9, 10, 11, 12](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
|
||||
* [Clang 3.9, 4.0, 5.0, 6.0, 7, 8, 9, 10, 11, 12, 13, 14, 15](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
|
||||
* [Visual Studio 2017, 2019, 2022](https://ci.appveyor.com/project/bblanchon/arduinojson/branch/6.x)
|
||||
* [GCC 5, 6, 7, 8, 9, 10, 11](https://github.com/bblanchon/ArduinoJson/actions?query=workflow%3A%22Continuous+Integration%22)
|
||||
* [Clang 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)
|
||||
* Passes all default checks of [clang-tidy](https://releases.llvm.org/10.0.0/tools/clang/tools/extra/docs/clang-tidy/)
|
||||
* Well documented
|
||||
* [Tutorials](https://arduinojson.org/v7/doc/deserialization/)
|
||||
* [Examples](https://arduinojson.org/v7/example/)
|
||||
* [How-tos](https://arduinojson.org/v7/example/)
|
||||
* [FAQ](https://arduinojson.org/v7/faq/)
|
||||
* [Troubleshooter](https://arduinojson.org/v7/troubleshooter/)
|
||||
* [Tutorials](https://arduinojson.org/v6/doc/deserialization/)
|
||||
* [Examples](https://arduinojson.org/v6/example/)
|
||||
* [How-tos](https://arduinojson.org/v6/example/)
|
||||
* [FAQ](https://arduinojson.org/v6/faq/)
|
||||
* [Troubleshooter](https://arduinojson.org/v6/troubleshooter/)
|
||||
* [Book](https://arduinojson.org/book/)
|
||||
* [Changelog](CHANGELOG.md)
|
||||
* Vibrant user community
|
||||
@ -103,9 +109,9 @@ ArduinoJson is a C++ JSON library for Arduino and IoT (Internet Of Things).
|
||||
Here is a program that parses a JSON document with ArduinoJson.
|
||||
|
||||
```c++
|
||||
const char* json = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
|
||||
char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
|
||||
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(1024);
|
||||
deserializeJson(doc, json);
|
||||
|
||||
const char* sensor = doc["sensor"];
|
||||
@ -114,14 +120,14 @@ double latitude = doc["data"][0];
|
||||
double longitude = doc["data"][1];
|
||||
```
|
||||
|
||||
See the [tutorial on arduinojson.org](https://arduinojson.org/v7/doc/deserialization/)
|
||||
See the [tutorial on arduinojson.org](https://arduinojson.org/v6/doc/deserialization/)
|
||||
|
||||
### Serialization
|
||||
|
||||
Here is a program that generates a JSON document with ArduinoJson:
|
||||
|
||||
```c++
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(1024);
|
||||
|
||||
doc["sensor"] = "gps";
|
||||
doc["time"] = 1351824120;
|
||||
@ -133,7 +139,7 @@ serializeJson(doc, Serial);
|
||||
// {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}
|
||||
```
|
||||
|
||||
See the [tutorial on arduinojson.org](https://arduinojson.org/v7/doc/serialization/)
|
||||
See the [tutorial on arduinojson.org](https://arduinojson.org/v6/doc/serialization/)
|
||||
|
||||
## Sponsors
|
||||
|
||||
@ -148,9 +154,6 @@ ArduinoJson is thankful to its sponsors. Please give them a visit; they deserve
|
||||
<a href="https://github.com/1technophile" rel="sponsored">
|
||||
<img alt="1technophile" src="https://avatars.githubusercontent.com/u/12672732?s=40&v=4">
|
||||
</a>
|
||||
<a href="https://github.com/LArkema" rel="sponsored">
|
||||
<img alt="LArkema" src="https://avatars.githubusercontent.com/u/38381313?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.
|
||||
|
@ -1,4 +1,4 @@
|
||||
version: 7.2.0.{build}
|
||||
version: 6.21.2.{build}
|
||||
environment:
|
||||
matrix:
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to store your project configuration in a file.
|
||||
@ -17,28 +17,35 @@
|
||||
// * CLK <-> pin 13
|
||||
// * CS <-> pin 4
|
||||
//
|
||||
// https://arduinojson.org/v7/example/config/
|
||||
// https://arduinojson.org/v6/example/config/
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <SD.h>
|
||||
#include <SPI.h>
|
||||
|
||||
// Our configuration structure.
|
||||
//
|
||||
// Never use a JsonDocument to store the configuration!
|
||||
// A JsonDocument is *not* a permanent storage; it's only a temporary storage
|
||||
// used during the serialization phase. See:
|
||||
// https://arduinojson.org/v6/faq/why-must-i-create-a-separate-config-object/
|
||||
struct Config {
|
||||
char hostname[64];
|
||||
int port;
|
||||
};
|
||||
|
||||
const char* filename = "/config.txt"; // <- SD library uses 8.3 filenames
|
||||
const char *filename = "/config.txt"; // <- SD library uses 8.3 filenames
|
||||
Config config; // <- global configuration object
|
||||
|
||||
// Loads the configuration from a file
|
||||
void loadConfiguration(const char* filename, Config& config) {
|
||||
void loadConfiguration(const char *filename, Config &config) {
|
||||
// Open file for reading
|
||||
File file = SD.open(filename);
|
||||
|
||||
// Allocate a temporary JsonDocument
|
||||
JsonDocument doc;
|
||||
// Don't forget to change the capacity to match your requirements.
|
||||
// Use https://arduinojson.org/v6/assistant to compute the capacity.
|
||||
StaticJsonDocument<512> doc;
|
||||
|
||||
// Deserialize the JSON document
|
||||
DeserializationError error = deserializeJson(doc, file);
|
||||
@ -56,7 +63,7 @@ void loadConfiguration(const char* filename, Config& config) {
|
||||
}
|
||||
|
||||
// Saves the configuration to a file
|
||||
void saveConfiguration(const char* filename, const Config& config) {
|
||||
void saveConfiguration(const char *filename, const Config &config) {
|
||||
// Delete existing file, otherwise the configuration is appended to the file
|
||||
SD.remove(filename);
|
||||
|
||||
@ -68,7 +75,9 @@ void saveConfiguration(const char* filename, const Config& config) {
|
||||
}
|
||||
|
||||
// Allocate a temporary JsonDocument
|
||||
JsonDocument doc;
|
||||
// Don't forget to change the capacity to match your requirements.
|
||||
// Use https://arduinojson.org/assistant to compute the capacity.
|
||||
StaticJsonDocument<256> doc;
|
||||
|
||||
// Set the values in the document
|
||||
doc["hostname"] = config.hostname;
|
||||
@ -84,7 +93,7 @@ void saveConfiguration(const char* filename, const Config& config) {
|
||||
}
|
||||
|
||||
// Prints the content of a file to the Serial
|
||||
void printFile(const char* filename) {
|
||||
void printFile(const char *filename) {
|
||||
// Open file for reading
|
||||
File file = SD.open(filename);
|
||||
if (!file) {
|
||||
@ -105,8 +114,7 @@ void printFile(const char* filename) {
|
||||
void setup() {
|
||||
// Initialize serial port
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
continue;
|
||||
while (!Serial) continue;
|
||||
|
||||
// Initialize SD library
|
||||
const int chipSelect = 4;
|
||||
@ -136,7 +144,7 @@ void loop() {
|
||||
// ------------------
|
||||
//
|
||||
// File is an unbuffered stream, which is not optimal for ArduinoJson.
|
||||
// See: https://arduinojson.org/v7/how-to/improve-speed/
|
||||
// See: https://arduinojson.org/v6/how-to/improve-speed/
|
||||
|
||||
// See also
|
||||
// --------
|
||||
|
@ -1,18 +1,17 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to use DeserializationOption::Filter
|
||||
//
|
||||
// https://arduinojson.org/v7/example/filter/
|
||||
// https://arduinojson.org/v6/example/filter/
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
void setup() {
|
||||
// Initialize serial port
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
continue;
|
||||
while (!Serial) continue;
|
||||
|
||||
// The huge input: an extract from OpenWeatherMap response
|
||||
auto input_json = F(
|
||||
@ -34,12 +33,12 @@ void setup() {
|
||||
"1000000,\"timezone\":0,\"sunrise\":1581492085,\"sunset\":1581527294}}");
|
||||
|
||||
// The filter: it contains "true" for each value we want to keep
|
||||
JsonDocument filter;
|
||||
StaticJsonDocument<200> filter;
|
||||
filter["list"][0]["dt"] = true;
|
||||
filter["list"][0]["main"]["temp"] = true;
|
||||
|
||||
// Deserialize the document
|
||||
JsonDocument doc;
|
||||
StaticJsonDocument<400> doc;
|
||||
deserializeJson(doc, input_json, DeserializationOption::Filter(filter));
|
||||
|
||||
// Print the result
|
||||
|
@ -1,32 +1,43 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to generate a JSON document with ArduinoJson.
|
||||
//
|
||||
// https://arduinojson.org/v7/example/generator/
|
||||
// https://arduinojson.org/v6/example/generator/
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
void setup() {
|
||||
// Initialize Serial port
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
continue;
|
||||
while (!Serial) continue;
|
||||
|
||||
// Allocate the JSON document
|
||||
JsonDocument doc;
|
||||
//
|
||||
// Inside the brackets, 200 is the RAM allocated to this document.
|
||||
// Don't forget to change this value to match your requirement.
|
||||
// Use https://arduinojson.org/v6/assistant to compute the capacity.
|
||||
StaticJsonDocument<200> doc;
|
||||
|
||||
// StaticJsonObject allocates memory on the stack, it can be
|
||||
// replaced by DynamicJsonDocument which allocates in the heap.
|
||||
//
|
||||
// DynamicJsonDocument doc(200);
|
||||
|
||||
// Add values in the document
|
||||
//
|
||||
doc["sensor"] = "gps";
|
||||
doc["time"] = 1351824120;
|
||||
|
||||
// Add an array
|
||||
JsonArray data = doc["data"].to<JsonArray>();
|
||||
// Add an array.
|
||||
//
|
||||
JsonArray data = doc.createNestedArray("data");
|
||||
data.add(48.756080);
|
||||
data.add(2.302038);
|
||||
|
||||
// Generate the minified JSON and send it to the Serial port
|
||||
// Generate the minified JSON and send it to the Serial port.
|
||||
//
|
||||
serializeJson(doc, Serial);
|
||||
// The above line prints:
|
||||
// {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}
|
||||
@ -34,7 +45,8 @@ void setup() {
|
||||
// Start a new line
|
||||
Serial.println();
|
||||
|
||||
// Generate the prettified JSON and send it to the Serial port
|
||||
// Generate the prettified JSON and send it to the Serial port.
|
||||
//
|
||||
serializeJsonPretty(doc, Serial);
|
||||
// The above line prints:
|
||||
// {
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to parse a JSON document in an HTTP response.
|
||||
@ -16,7 +16,7 @@
|
||||
// ]
|
||||
// }
|
||||
//
|
||||
// https://arduinojson.org/v7/example/http-client/
|
||||
// https://arduinojson.org/v6/example/http-client/
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <Ethernet.h>
|
||||
@ -25,8 +25,7 @@
|
||||
void setup() {
|
||||
// Initialize Serial port
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
continue;
|
||||
while (!Serial) continue;
|
||||
|
||||
// Initialize Ethernet library
|
||||
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
|
||||
@ -78,7 +77,9 @@ void setup() {
|
||||
}
|
||||
|
||||
// Allocate the JSON document
|
||||
JsonDocument doc;
|
||||
// Use https://arduinojson.org/v6/assistant to compute the capacity.
|
||||
const size_t capacity = JSON_OBJECT_SIZE(3) + JSON_ARRAY_SIZE(2) + 60;
|
||||
DynamicJsonDocument doc(capacity);
|
||||
|
||||
// Parse JSON object
|
||||
DeserializationError error = deserializeJson(doc, client);
|
||||
@ -108,7 +109,7 @@ void loop() {
|
||||
// ------------------
|
||||
//
|
||||
// EthernetClient is an unbuffered stream, which is not optimal for ArduinoJson.
|
||||
// See: https://arduinojson.org/v7/how-to/improve-speed/
|
||||
// See: https://arduinojson.org/v6/how-to/improve-speed/
|
||||
|
||||
// See also
|
||||
// --------
|
||||
|
@ -1,37 +1,52 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to deserialize a JSON document with ArduinoJson.
|
||||
//
|
||||
// https://arduinojson.org/v7/example/parser/
|
||||
// https://arduinojson.org/v6/example/parser/
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
void setup() {
|
||||
// Initialize serial port
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
continue;
|
||||
while (!Serial) continue;
|
||||
|
||||
// Allocate the JSON document
|
||||
JsonDocument doc;
|
||||
//
|
||||
// Inside the brackets, 200 is the capacity of the memory pool in bytes.
|
||||
// Don't forget to change this value to match your JSON document.
|
||||
// Use https://arduinojson.org/v6/assistant to compute the capacity.
|
||||
StaticJsonDocument<200> doc;
|
||||
|
||||
// StaticJsonDocument<N> allocates memory on the stack, it can be
|
||||
// replaced by DynamicJsonDocument which allocates in the heap.
|
||||
//
|
||||
// DynamicJsonDocument doc(200);
|
||||
|
||||
// JSON input string.
|
||||
const char* json =
|
||||
//
|
||||
// Using a char[], as shown here, enables the "zero-copy" mode. This mode uses
|
||||
// the minimal amount of memory because the JsonDocument stores pointers to
|
||||
// the input buffer.
|
||||
// If you use another type of input, ArduinoJson must copy the strings from
|
||||
// the input to the JsonDocument, so you need to increase the capacity of the
|
||||
// JsonDocument.
|
||||
char json[] =
|
||||
"{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
|
||||
|
||||
// Deserialize the JSON document
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
|
||||
// Test if parsing succeeds
|
||||
// Test if parsing succeeds.
|
||||
if (error) {
|
||||
Serial.print(F("deserializeJson() failed: "));
|
||||
Serial.println(error.f_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch the values
|
||||
// Fetch values.
|
||||
//
|
||||
// Most of the time, you can rely on the implicit casts.
|
||||
// In other case, you can do doc["time"].as<long>();
|
||||
@ -40,7 +55,7 @@ void setup() {
|
||||
double latitude = doc["data"][0];
|
||||
double longitude = doc["data"][1];
|
||||
|
||||
// Print the values
|
||||
// Print values.
|
||||
Serial.println(sensor);
|
||||
Serial.println(time);
|
||||
Serial.println(latitude, 6);
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to implement an HTTP server that sends a JSON document
|
||||
@ -13,7 +13,7 @@
|
||||
// "digital": [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0]
|
||||
// }
|
||||
//
|
||||
// https://arduinojson.org/v7/example/http-server/
|
||||
// https://arduinojson.org/v6/example/http-server/
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <Ethernet.h>
|
||||
@ -25,8 +25,7 @@ EthernetServer server(80);
|
||||
void setup() {
|
||||
// Initialize serial port
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
continue;
|
||||
while (!Serial) continue;
|
||||
|
||||
// Initialize Ethernet libary
|
||||
if (!Ethernet.begin(mac)) {
|
||||
@ -53,14 +52,14 @@ void loop() {
|
||||
Serial.println(F("New client"));
|
||||
|
||||
// Read the request (we ignore the content in this example)
|
||||
while (client.available())
|
||||
client.read();
|
||||
while (client.available()) client.read();
|
||||
|
||||
// Allocate a temporary JsonDocument
|
||||
JsonDocument doc;
|
||||
// Use https://arduinojson.org/v6/assistant to compute the capacity.
|
||||
StaticJsonDocument<500> doc;
|
||||
|
||||
// Create the "analog" array
|
||||
JsonArray analogValues = doc["analog"].to<JsonArray>();
|
||||
JsonArray analogValues = doc.createNestedArray("analog");
|
||||
for (int pin = 0; pin < 6; pin++) {
|
||||
// Read the analog input
|
||||
int value = analogRead(pin);
|
||||
@ -70,7 +69,7 @@ void loop() {
|
||||
}
|
||||
|
||||
// Create the "digital" array
|
||||
JsonArray digitalValues = doc["digital"].to<JsonArray>();
|
||||
JsonArray digitalValues = doc.createNestedArray("digital");
|
||||
for (int pin = 0; pin < 14; pin++) {
|
||||
// Read the digital input
|
||||
int value = digitalRead(pin);
|
||||
@ -102,7 +101,7 @@ void loop() {
|
||||
// ------------------
|
||||
//
|
||||
// EthernetClient is an unbuffered stream, which is not optimal for ArduinoJson.
|
||||
// See: https://arduinojson.org/v7/how-to/improve-speed/
|
||||
// See: https://arduinojson.org/v6/how-to/improve-speed/
|
||||
|
||||
// See also
|
||||
// --------
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to send a JSON document to a UDP socket.
|
||||
@ -17,7 +17,7 @@
|
||||
// $ ncat -ulp 8888
|
||||
// See https://nmap.org/ncat/
|
||||
//
|
||||
// https://arduinojson.org/v7/example/udp-beacon/
|
||||
// https://arduinojson.org/v6/example/udp-beacon/
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <Ethernet.h>
|
||||
@ -32,8 +32,7 @@ EthernetUDP udp;
|
||||
void setup() {
|
||||
// Initialize serial port
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
continue;
|
||||
while (!Serial) continue;
|
||||
|
||||
// Initialize Ethernet libary
|
||||
if (!Ethernet.begin(mac)) {
|
||||
@ -47,10 +46,11 @@ void setup() {
|
||||
|
||||
void loop() {
|
||||
// Allocate a temporary JsonDocument
|
||||
JsonDocument doc;
|
||||
// Use https://arduinojson.org/v6/assistant to compute the capacity.
|
||||
StaticJsonDocument<500> doc;
|
||||
|
||||
// Create the "analog" array
|
||||
JsonArray analogValues = doc["analog"].to<JsonArray>();
|
||||
JsonArray analogValues = doc.createNestedArray("analog");
|
||||
for (int pin = 0; pin < 6; pin++) {
|
||||
// Read the analog input
|
||||
int value = analogRead(pin);
|
||||
@ -60,7 +60,7 @@ void loop() {
|
||||
}
|
||||
|
||||
// Create the "digital" array
|
||||
JsonArray digitalValues = doc["digital"].to<JsonArray>();
|
||||
JsonArray digitalValues = doc.createNestedArray("digital");
|
||||
for (int pin = 0; pin < 14; pin++) {
|
||||
// Read the digital input
|
||||
int value = digitalRead(pin);
|
||||
@ -90,7 +90,7 @@ void loop() {
|
||||
// ------------------
|
||||
//
|
||||
// EthernetUDP is an unbuffered stream, which is not optimal for ArduinoJson.
|
||||
// See: https://arduinojson.org/v7/how-to/improve-speed/
|
||||
// See: https://arduinojson.org/v6/how-to/improve-speed/
|
||||
|
||||
// See also
|
||||
// --------
|
||||
|
@ -1,24 +1,39 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to deserialize a MessagePack document with
|
||||
// ArduinoJson.
|
||||
//
|
||||
// https://arduinojson.org/v7/example/msgpack-parser/
|
||||
// https://arduinojson.org/v6/example/msgpack-parser/
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
void setup() {
|
||||
// Initialize serial port
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
continue;
|
||||
while (!Serial) continue;
|
||||
|
||||
// Allocate the JSON document
|
||||
JsonDocument doc;
|
||||
//
|
||||
// Inside the brackets, 200 is the capacity of the memory pool in bytes.
|
||||
// Don't forget to change this value to match your JSON document.
|
||||
// Use https://arduinojson.org/v6/assistant to compute the capacity.
|
||||
StaticJsonDocument<200> doc;
|
||||
|
||||
// The MessagePack input string
|
||||
// StaticJsonObject allocates memory on the stack, it can be
|
||||
// replaced by DynamicJsonObject which allocates in the heap.
|
||||
//
|
||||
// DynamicJsonObject doc(200);
|
||||
|
||||
// MessagePack input string.
|
||||
//
|
||||
// Using a char[], as shown here, enables the "zero-copy" mode. This mode uses
|
||||
// the minimal amount of memory because the JsonDocument stores pointers to
|
||||
// the input buffer.
|
||||
// If you use another type of input, ArduinoJson must copy the strings from
|
||||
// the input to the JsonDocument, so you need to increase the capacity of the
|
||||
// JsonDocument.
|
||||
uint8_t input[] = {131, 166, 115, 101, 110, 115, 111, 114, 163, 103, 112, 115,
|
||||
164, 116, 105, 109, 101, 206, 80, 147, 50, 248, 164, 100,
|
||||
97, 116, 97, 146, 203, 64, 72, 96, 199, 58, 188, 148,
|
||||
@ -30,17 +45,16 @@ void setup() {
|
||||
// "data": [48.75608, 2.302038]
|
||||
// }
|
||||
|
||||
// Parse the input
|
||||
DeserializationError error = deserializeMsgPack(doc, input);
|
||||
|
||||
// Test if parsing succeeded
|
||||
// Test if parsing succeeded.
|
||||
if (error) {
|
||||
Serial.print("deserializeMsgPack() failed: ");
|
||||
Serial.println(error.f_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch the values
|
||||
// Fetch values.
|
||||
//
|
||||
// Most of the time, you can rely on the implicit casts.
|
||||
// In other case, you can do doc["time"].as<long>();
|
||||
@ -49,7 +63,7 @@ void setup() {
|
||||
double latitude = doc["data"][0];
|
||||
double longitude = doc["data"][1];
|
||||
|
||||
// Print the values
|
||||
// Print values.
|
||||
Serial.println(sensor);
|
||||
Serial.println(time);
|
||||
Serial.println(latitude, 6);
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
//
|
||||
// This example shows the different ways you can use Flash strings with
|
||||
@ -9,12 +9,12 @@
|
||||
// JsonDocument. Prefer plain old char*, as they are more efficient in term of
|
||||
// code size, speed, and memory usage.
|
||||
//
|
||||
// https://arduinojson.org/v7/example/progmem/
|
||||
// https://arduinojson.org/v6/example/progmem/
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
void setup() {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(1024);
|
||||
|
||||
// You can use a Flash String as your JSON input.
|
||||
// WARNING: the strings in the input will be duplicated in the JsonDocument.
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
//
|
||||
// This example shows the different ways you can use String with ArduinoJson.
|
||||
@ -8,12 +8,12 @@
|
||||
// JsonDocument. Prefer plain old char[], as they are more efficient in term of
|
||||
// code size, speed, and memory usage.
|
||||
//
|
||||
// https://arduinojson.org/v7/example/string/
|
||||
// https://arduinojson.org/v6/example/string/
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
void setup() {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(1024);
|
||||
|
||||
// You can use a String as your JSON input.
|
||||
// WARNING: the string in the input will be duplicated in the JsonDocument.
|
||||
@ -55,6 +55,7 @@ void setup() {
|
||||
}
|
||||
|
||||
// Lastly, you can print the resulting JSON to a String
|
||||
// WARNING: it doesn't replace the content but appends to it
|
||||
String output;
|
||||
serializeJson(doc, output);
|
||||
}
|
||||
|
@ -1,7 +1,3 @@
|
||||
if(NOT DEFINED COVERAGE)
|
||||
set(COVERAGE OFF)
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
|
||||
add_compile_options(
|
||||
-pedantic
|
||||
@ -34,20 +30,10 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9) AND(NOT ${COVERAGE}))
|
||||
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.8) AND(NOT ${COVERAGE}))
|
||||
add_compile_options(-g -Og)
|
||||
else() # GCC 4.8
|
||||
add_compile_options(
|
||||
-g
|
||||
-O0 # GCC 4.8 doesn't support -Og
|
||||
-Wno-shadow # allow the same name for a function parameter and a member functions
|
||||
-Wp,-w # Disable preprocessing warnings (see below)
|
||||
)
|
||||
# GCC 4.8 doesn't support __has_include, so we need to help him
|
||||
add_definitions(
|
||||
-DARDUINOJSON_ENABLE_STD_STRING=1
|
||||
-DARDUINOJSON_ENABLE_STD_STREAM=1
|
||||
)
|
||||
else()
|
||||
add_compile_options(-g -O0)
|
||||
endif()
|
||||
|
||||
add_compile_options(
|
||||
@ -78,9 +64,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
add_compile_options(-stdlib=libc++)
|
||||
link_libraries(c++ m)
|
||||
|
||||
if((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0) AND(NOT ${COVERAGE}))
|
||||
add_compile_options(-g -Og)
|
||||
else()
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ArduinoJson - https://arduinojson.org
|
||||
# Copyright © 2014-2024, Benoit BLANCHON
|
||||
# Copyright © 2014-2023, Benoit BLANCHON
|
||||
# MIT License
|
||||
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ArduinoJson - https://arduinojson.org
|
||||
# Copyright © 2014-2024, Benoit BLANCHON
|
||||
# Copyright © 2014-2023, Benoit BLANCHON
|
||||
# MIT License
|
||||
|
||||
idf_component_register(
|
||||
|
@ -1,12 +1,12 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
extern "C" void app_main() {
|
||||
char buffer[256];
|
||||
JsonDocument doc;
|
||||
StaticJsonDocument<200> doc;
|
||||
|
||||
doc["hello"] = "world";
|
||||
serializeJson(doc, buffer);
|
||||
|
@ -4,15 +4,15 @@ static_assert(ARDUINOJSON_ENABLE_PROGMEM == 1, "ARDUINOJSON_ENABLE_PROGMEM");
|
||||
|
||||
static_assert(ARDUINOJSON_USE_LONG_LONG == 0, "ARDUINOJSON_USE_LONG_LONG");
|
||||
|
||||
static_assert(ARDUINOJSON_SLOT_ID_SIZE == 1, "ARDUINOJSON_SLOT_ID_SIZE");
|
||||
|
||||
static_assert(ARDUINOJSON_POOL_CAPACITY == 16, "ARDUINOJSON_POOL_CAPACITY");
|
||||
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 == 0, "ARDUINOJSON_USE_DOUBLE");
|
||||
static_assert(ARDUINOJSON_USE_DOUBLE == 1, "ARDUINOJSON_USE_DOUBLE");
|
||||
|
||||
static_assert(ArduinoJson::detail::ResourceManager::slotSize == 6, "slot size");
|
||||
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 8,
|
||||
"sizeof(VariantSlot)");
|
||||
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
|
@ -2,15 +2,15 @@
|
||||
|
||||
static_assert(ARDUINOJSON_USE_LONG_LONG == 1, "ARDUINOJSON_USE_LONG_LONG");
|
||||
|
||||
static_assert(ARDUINOJSON_SLOT_ID_SIZE == 2, "ARDUINOJSON_SLOT_ID_SIZE");
|
||||
|
||||
static_assert(ARDUINOJSON_POOL_CAPACITY == 128, "ARDUINOJSON_POOL_CAPACITY");
|
||||
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(ArduinoJson::detail::ResourceManager::slotSize == 8, "slot size");
|
||||
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 16,
|
||||
"sizeof(VariantSlot)");
|
||||
|
||||
void setup() {}
|
||||
void loop() {}
|
||||
|
@ -2,15 +2,14 @@
|
||||
|
||||
static_assert(ARDUINOJSON_USE_LONG_LONG == 1, "ARDUINOJSON_USE_LONG_LONG");
|
||||
|
||||
static_assert(ARDUINOJSON_SLOT_ID_SIZE == 4, "ARDUINOJSON_SLOT_ID_SIZE");
|
||||
|
||||
static_assert(ARDUINOJSON_POOL_CAPACITY == 256, "ARDUINOJSON_POOL_CAPACITY");
|
||||
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(ArduinoJson::detail::ResourceManager::slotSize == 16,
|
||||
"slot size");
|
||||
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 32,
|
||||
"sizeof(VariantSlot)");
|
||||
|
||||
int main() {}
|
||||
|
@ -2,14 +2,14 @@
|
||||
|
||||
static_assert(ARDUINOJSON_USE_LONG_LONG == 1, "ARDUINOJSON_USE_LONG_LONG");
|
||||
|
||||
static_assert(ARDUINOJSON_SLOT_ID_SIZE == 2, "ARDUINOJSON_SLOT_ID_SIZE");
|
||||
|
||||
static_assert(ARDUINOJSON_POOL_CAPACITY == 128, "ARDUINOJSON_POOL_CAPACITY");
|
||||
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(ArduinoJson::detail::ResourceManager::slotSize == 8, "slot size");
|
||||
static_assert(sizeof(ArduinoJson::detail::VariantSlot) == 16,
|
||||
"sizeof(VariantSlot)");
|
||||
|
||||
int main() {}
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ArduinoJson - https://arduinojson.org
|
||||
# Copyright © 2014-2024, Benoit BLANCHON
|
||||
# Copyright © 2014-2023, Benoit BLANCHON
|
||||
# MIT License
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
@ -52,16 +52,7 @@ macro(add_fuzzer name)
|
||||
)
|
||||
endmacro()
|
||||
|
||||
# Needs Clang 6+ to compile
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 6)
|
||||
if(DEFINED ENV{GITHUB_ACTIONS} AND CMAKE_CXX_COMPILER_VERSION MATCHES "^11\\.")
|
||||
# Clang 11 fails on GitHub Actions with the following error:
|
||||
# > ERROR: UndefinedBehaviorSanitizer failed to allocate 0x0 (0) bytes of SetAlternateSignalStack (error code: 22)
|
||||
# > Sanitizer CHECK failed: /build/llvm-toolchain-11-mnvtwk/llvm-toolchain-11-11.1.0/compiler-rt/lib/sanitizer_common/sanitizer_common.cpp:54 ((0 && "unable to mmap")) != (0) (0, 0)
|
||||
message(WARNING "Fuzzing is disabled on GitHub Actions to workaround a bug in Clang 11")
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6)
|
||||
add_fuzzer(json)
|
||||
add_fuzzer(msgpack)
|
||||
endif()
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
DeserializationError error = deserializeJson(doc, data, size);
|
||||
if (!error) {
|
||||
std::string json;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
DeserializationError error = deserializeMsgPack(doc, data, size);
|
||||
if (!error) {
|
||||
std::string json;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
// This file is NOT use by Google's OSS fuzz
|
||||
|
23
extras/scripts/build-arduino-package.sh
Executable file
23
extras/scripts/build-arduino-package.sh
Executable file
@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eu
|
||||
|
||||
INPUT=$1
|
||||
OUTPUT=$2
|
||||
|
||||
cd "$INPUT"
|
||||
|
||||
# remove existing file
|
||||
rm -f "$OUTPUT"
|
||||
|
||||
# create zip
|
||||
7z a "$OUTPUT" \
|
||||
-xr!.vs \
|
||||
CHANGELOG.md \
|
||||
examples \
|
||||
src \
|
||||
keywords.txt \
|
||||
library.properties \
|
||||
LICENSE.txt \
|
||||
README.md \
|
||||
ArduinoJson.h
|
@ -4,14 +4,14 @@ set -eu
|
||||
|
||||
VERSION="$1"
|
||||
CHANGELOG="$2"
|
||||
ARDUINOJSON_H="$3"
|
||||
FRONTMATTER="$3"
|
||||
|
||||
cat << END
|
||||
---
|
||||
branch: v7
|
||||
branch: v6
|
||||
version: $VERSION
|
||||
date: '$(date +'%Y-%m-%d')'
|
||||
$(extras/scripts/wandbox/publish.sh "$ARDUINOJSON_H")
|
||||
$(cat "$FRONTMATTER")
|
||||
---
|
||||
|
||||
$(awk '/\* /{ FOUND=1; print; next } { if (FOUND) exit}' "$CHANGELOG")
|
||||
|
@ -14,5 +14,5 @@ cp -r "$SOURCE_DIR/src" "$WORK_DIR/"
|
||||
cp -r "$SOURCE_DIR/examples" "$WORK_DIR/"
|
||||
|
||||
cd "$WORK_DIR"
|
||||
particle library upload
|
||||
particle library publish
|
||||
particle library upload -v
|
||||
particle library publish -v
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
set -eu
|
||||
|
||||
which awk sed jq curl perl >/dev/null
|
||||
which awk sed jq 7z curl perl >/dev/null
|
||||
|
||||
cd "$(dirname "$0")/../.."
|
||||
|
||||
@ -15,7 +15,6 @@ VERSION="$1"
|
||||
DATE=$(date +%F)
|
||||
TAG="v$VERSION"
|
||||
VERSION_REGEX='[0-9]+\.[0-9]+\.[0-9]+(-[a-z0-9]+)?'
|
||||
STARS=$(curl -s https://api.github.com/repos/bblanchon/ArduinoJson | jq '.stargazers_count')
|
||||
|
||||
update_version_in_source () {
|
||||
IFS=".-" read MAJOR MINOR REVISION EXTRA < <(echo "$VERSION")
|
||||
@ -30,25 +29,16 @@ update_version_in_source () {
|
||||
sed -i~ -bE "s/(project\\s*\\(ArduinoJson\\s+VERSION\\s+).*?\\)/\\1$MAJOR.$MINOR.$REVISION)/" CMakeLists.txt
|
||||
rm CMakeLists.txt~
|
||||
|
||||
sed -i~ -bE \
|
||||
-e "s/\"version\":.*$/\"version\": \"$VERSION\",/" \
|
||||
-e "s/[0-9]+ stars/$STARS stars/" \
|
||||
library.json
|
||||
sed -i~ -bE "s/\"version\":.*$/\"version\": \"$VERSION\",/" library.json
|
||||
rm library.json~
|
||||
|
||||
sed -i~ -bE \
|
||||
-e "s/version=.*$/version=$VERSION/" \
|
||||
-e "s/[0-9]+ stars/$STARS stars/" \
|
||||
library.properties
|
||||
sed -i~ -bE "s/version=.*$/version=$VERSION/" library.properties
|
||||
rm library.properties~
|
||||
|
||||
sed -i~ -bE "s/version: .*$/version: $VERSION.{build}/" appveyor.yml
|
||||
rm appveyor.yml~
|
||||
|
||||
sed -i~ -bE \
|
||||
-e "s/^version: .*$/version: \"$VERSION\"/" \
|
||||
-e "s/[0-9]+ stars/$STARS stars/" \
|
||||
idf_component.yml
|
||||
sed -i~ -bE "s/^version: .*$/version: \"$VERSION\"/" idf_component.yml
|
||||
rm idf_component.yml~
|
||||
|
||||
sed -i~ -bE \
|
||||
@ -80,8 +70,10 @@ commit_new_version
|
||||
add_tag
|
||||
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/get-release-page.sh "$VERSION" "CHANGELOG.md" "../ArduinoJson-$TAG.h" > "../ArduinoJson-$TAG.md"
|
||||
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"
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to generate a JSON document with ArduinoJson.
|
||||
@ -9,18 +9,35 @@
|
||||
|
||||
int main() {
|
||||
// Allocate the JSON document
|
||||
JsonDocument doc;
|
||||
//
|
||||
// Inside the brackets, 200 is the RAM allocated to this document.
|
||||
// Don't forget to change this value to match your requirement.
|
||||
// Use https://arduinojson.org/v6/assistant to compute the capacity.
|
||||
StaticJsonDocument<200> doc;
|
||||
|
||||
// Add values in the document.
|
||||
// StaticJsonObject allocates memory on the stack, it can be
|
||||
// replaced by DynamicJsonDocument which allocates in the heap.
|
||||
//
|
||||
// DynamicJsonDocument doc(200);
|
||||
|
||||
// StaticJsonObject allocates memory on the stack, it can be
|
||||
// replaced by DynamicJsonDocument which allocates in the heap.
|
||||
//
|
||||
// DynamicJsonDocument doc(200);
|
||||
|
||||
// Add values in the document
|
||||
//
|
||||
doc["sensor"] = "gps";
|
||||
doc["time"] = 1351824120;
|
||||
|
||||
// Add an array
|
||||
JsonArray data = doc["data"].to<JsonArray>();
|
||||
// Add an array.
|
||||
//
|
||||
JsonArray data = doc.createNestedArray("data");
|
||||
data.add(48.756080);
|
||||
data.add(2.302038);
|
||||
|
||||
// Generate the minified JSON and send it to STDOUT
|
||||
//
|
||||
serializeJson(doc, std::cout);
|
||||
// The above line prints:
|
||||
// {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}
|
||||
@ -29,6 +46,7 @@ int main() {
|
||||
std::cout << std::endl;
|
||||
|
||||
// Generate the prettified JSON and send it to STDOUT
|
||||
//
|
||||
serializeJsonPretty(doc, std::cout);
|
||||
// The above line prints:
|
||||
// {
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to deserialize a JSON document with ArduinoJson.
|
||||
@ -9,22 +9,38 @@
|
||||
|
||||
int main() {
|
||||
// Allocate the JSON document
|
||||
JsonDocument doc;
|
||||
//
|
||||
// Inside the brackets, 200 is the capacity of the memory pool in bytes.
|
||||
// Don't forget to change this value to match your JSON document.
|
||||
// Use https://arduinojson.org/v6/assistant to compute the capacity.
|
||||
StaticJsonDocument<300> doc;
|
||||
|
||||
// JSON input string
|
||||
const char* json =
|
||||
// StaticJsonDocument<N> allocates memory on the stack, it can be
|
||||
// replaced by DynamicJsonDocument which allocates in the heap.
|
||||
//
|
||||
// DynamicJsonDocument doc(200);
|
||||
|
||||
// JSON input string.
|
||||
//
|
||||
// Using a char[], as shown here, enables the "zero-copy" mode. This mode uses
|
||||
// the minimal amount of memory because the JsonDocument stores pointers to
|
||||
// the input buffer.
|
||||
// If you use another type of input, ArduinoJson must copy the strings from
|
||||
// the input to the JsonDocument, so you need to increase the capacity of the
|
||||
// JsonDocument.
|
||||
char json[] =
|
||||
"{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
|
||||
|
||||
// Deserialize the JSON document
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
|
||||
// Test if parsing succeeds
|
||||
// Test if parsing succeeds.
|
||||
if (error) {
|
||||
std::cerr << "deserializeJson() failed: " << error.c_str() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Fetch the values
|
||||
// Fetch values.
|
||||
//
|
||||
// Most of the time, you can rely on the implicit casts.
|
||||
// In other case, you can do doc["time"].as<long>();
|
||||
@ -33,7 +49,7 @@ int main() {
|
||||
double latitude = doc["data"][0];
|
||||
double longitude = doc["data"][1];
|
||||
|
||||
// Print the values
|
||||
// Print values.
|
||||
std::cout << sensor << std::endl;
|
||||
std::cout << time << std::endl;
|
||||
std::cout << latitude << std::endl;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
//
|
||||
// This example shows how to generate a JSON document with ArduinoJson.
|
||||
@ -9,9 +9,22 @@
|
||||
|
||||
int main() {
|
||||
// Allocate the JSON document
|
||||
JsonDocument doc;
|
||||
//
|
||||
// Inside the brackets, 300 is the size of the memory pool in bytes.
|
||||
// Don't forget to change this value to match your JSON document.
|
||||
// Use https://arduinojson.org/assistant to compute the capacity.
|
||||
StaticJsonDocument<300> doc;
|
||||
|
||||
// The MessagePack input string
|
||||
// StaticJsonObject allocates memory on the stack, it can be
|
||||
// replaced by DynamicJsonObject which allocates in the heap.
|
||||
//
|
||||
// DynamicJsonObject doc(200);
|
||||
|
||||
// MessagePack input string.
|
||||
//
|
||||
// It's better to use a char[] as shown here.
|
||||
// If you use a const char* or a String, ArduinoJson will
|
||||
// have to make a copy of the input in the JsonBuffer.
|
||||
uint8_t input[] = {131, 166, 115, 101, 110, 115, 111, 114, 163, 103, 112, 115,
|
||||
164, 116, 105, 109, 101, 206, 80, 147, 50, 248, 164, 100,
|
||||
97, 116, 97, 146, 203, 64, 72, 96, 199, 58, 188, 148,
|
||||
@ -23,16 +36,20 @@ int main() {
|
||||
// "data": [48.75608, 2.302038]
|
||||
// }
|
||||
|
||||
// Parse the input
|
||||
// doc of the object tree.
|
||||
//
|
||||
// It's a reference to the JsonObject, the actual bytes are inside the
|
||||
// JsonBuffer with all the other nodes of the object tree.
|
||||
// Memory is freed when jsonBuffer goes out of scope.
|
||||
DeserializationError error = deserializeMsgPack(doc, input);
|
||||
|
||||
// Test if parsing succeeds
|
||||
// Test if parsing succeeds.
|
||||
if (error) {
|
||||
std::cerr << "deserializeMsgPack() failed: " << error.c_str() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Fetch the values
|
||||
// Fetch values.
|
||||
//
|
||||
// Most of the time, you can rely on the implicit casts.
|
||||
// In other case, you can do doc["time"].as<long>();
|
||||
@ -41,7 +58,7 @@ int main() {
|
||||
double latitude = doc["data"][0];
|
||||
double longitude = doc["data"][1];
|
||||
|
||||
// Print the values
|
||||
// Print values.
|
||||
std::cout << sensor << std::endl;
|
||||
std::cout << time << std::endl;
|
||||
std::cout << latitude << std::endl;
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ArduinoJson - https://arduinojson.org
|
||||
# Copyright © 2014-2024, Benoit BLANCHON
|
||||
# Copyright © 2014-2023, Benoit BLANCHON
|
||||
# MIT License
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
@ -12,19 +12,15 @@ link_libraries(ArduinoJson catch)
|
||||
include_directories(Helpers)
|
||||
add_subdirectory(Cpp17)
|
||||
add_subdirectory(Cpp20)
|
||||
add_subdirectory(Deprecated)
|
||||
add_subdirectory(FailingBuilds)
|
||||
add_subdirectory(IntegrationTests)
|
||||
add_subdirectory(JsonArray)
|
||||
add_subdirectory(JsonArrayConst)
|
||||
add_subdirectory(JsonDeserializer)
|
||||
add_subdirectory(JsonDocument)
|
||||
add_subdirectory(JsonObject)
|
||||
add_subdirectory(JsonObjectConst)
|
||||
add_subdirectory(JsonSerializer)
|
||||
add_subdirectory(JsonVariant)
|
||||
add_subdirectory(JsonVariantConst)
|
||||
add_subdirectory(ResourceManager)
|
||||
add_subdirectory(MemoryPool)
|
||||
add_subdirectory(Misc)
|
||||
add_subdirectory(MixedConfiguration)
|
||||
add_subdirectory(MsgPackDeserializer)
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ArduinoJson - https://arduinojson.org
|
||||
# Copyright © 2014-2024, Benoit BLANCHON
|
||||
# Copyright © 2014-2023, Benoit BLANCHON
|
||||
# MIT License
|
||||
|
||||
if(MSVC_VERSION LESS 1910)
|
||||
|
@ -1,28 +1,14 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
// we expect ArduinoJson.h to include <string_view>
|
||||
// but we don't want it to included accidentally
|
||||
#undef ARDUINO
|
||||
#define ARDUINOJSON_ENABLE_STD_STREAM 0
|
||||
#define ARDUINOJSON_ENABLE_STD_STRING 0
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
#include "Literals.hpp"
|
||||
#include <string_view>
|
||||
|
||||
#if !ARDUINOJSON_ENABLE_STRING_VIEW
|
||||
# error ARDUINOJSON_ENABLE_STRING_VIEW must be set to 1
|
||||
#endif
|
||||
|
||||
using ArduinoJson::detail::sizeofArray;
|
||||
|
||||
TEST_CASE("string_view") {
|
||||
SpyingAllocator spy;
|
||||
JsonDocument doc(&spy);
|
||||
StaticJsonDocument<256> doc;
|
||||
JsonVariant variant = doc.to<JsonVariant>();
|
||||
|
||||
SECTION("deserializeJson()") {
|
||||
@ -33,7 +19,7 @@ TEST_CASE("string_view") {
|
||||
|
||||
SECTION("JsonDocument::set()") {
|
||||
doc.set(std::string_view("123", 2));
|
||||
REQUIRE(doc.as<std::string_view>() == "12");
|
||||
REQUIRE(doc.as<std::string>() == "12");
|
||||
}
|
||||
|
||||
SECTION("JsonDocument::operator[]() const") {
|
||||
@ -67,15 +53,16 @@ TEST_CASE("string_view") {
|
||||
|
||||
SECTION("String deduplication") {
|
||||
doc.add(std::string_view("example one", 7));
|
||||
doc.add(std::string_view("example two", 7));
|
||||
doc.add(std::string_view("example\0tree", 12));
|
||||
doc.add(std::string_view("example\0tree and a half", 12));
|
||||
REQUIRE(doc.memoryUsage() == JSON_ARRAY_SIZE(1) + 8);
|
||||
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
Allocate(sizeofString("example")),
|
||||
Allocate(sizeofString("example tree")),
|
||||
});
|
||||
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>()") {
|
||||
@ -93,7 +80,7 @@ TEST_CASE("string_view") {
|
||||
}
|
||||
|
||||
SECTION("String containing NUL") {
|
||||
doc.set("hello\0world"_s);
|
||||
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));
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ArduinoJson - https://arduinojson.org
|
||||
# Copyright © 2014-2024, Benoit BLANCHON
|
||||
# Copyright © 2014-2023, Benoit BLANCHON
|
||||
# MIT License
|
||||
|
||||
if(MSVC_VERSION LESS 1910)
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <string>
|
||||
|
||||
TEST_CASE("C++20 smoke test") {
|
||||
JsonDocument doc;
|
||||
StaticJsonDocument<128> doc;
|
||||
|
||||
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||
REQUIRE(doc["hello"] == "world");
|
||||
|
@ -1,69 +0,0 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
using ArduinoJson::detail::is_base_of;
|
||||
|
||||
static std::string allocatorLog;
|
||||
|
||||
struct CustomAllocator {
|
||||
CustomAllocator() {
|
||||
allocatorLog = "";
|
||||
}
|
||||
|
||||
void* allocate(size_t n) {
|
||||
allocatorLog += "A";
|
||||
return malloc(n);
|
||||
}
|
||||
|
||||
void deallocate(void* p) {
|
||||
free(p);
|
||||
allocatorLog += "D";
|
||||
}
|
||||
|
||||
void* reallocate(void* p, size_t n) {
|
||||
allocatorLog += "R";
|
||||
return realloc(p, n);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_CASE("BasicJsonDocument") {
|
||||
allocatorLog.clear();
|
||||
|
||||
SECTION("is a JsonDocument") {
|
||||
REQUIRE(
|
||||
is_base_of<JsonDocument, BasicJsonDocument<CustomAllocator>>::value ==
|
||||
true);
|
||||
}
|
||||
|
||||
SECTION("deserialize / serialize") {
|
||||
BasicJsonDocument<CustomAllocator> doc(256);
|
||||
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||
REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\"}");
|
||||
doc.clear();
|
||||
REQUIRE(allocatorLog == "ARAARDDD");
|
||||
}
|
||||
|
||||
SECTION("copy") {
|
||||
BasicJsonDocument<CustomAllocator> doc(256);
|
||||
doc["hello"] = "world";
|
||||
auto copy = doc;
|
||||
REQUIRE(copy.as<std::string>() == "{\"hello\":\"world\"}");
|
||||
REQUIRE(allocatorLog == "AA");
|
||||
}
|
||||
|
||||
SECTION("capacity") {
|
||||
BasicJsonDocument<CustomAllocator> doc(256);
|
||||
REQUIRE(doc.capacity() == 256);
|
||||
}
|
||||
|
||||
SECTION("garbageCollect()") {
|
||||
BasicJsonDocument<CustomAllocator> doc(256);
|
||||
doc.garbageCollect();
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
# ArduinoJson - https://arduinojson.org
|
||||
# Copyright © 2014-2024, Benoit BLANCHON
|
||||
# MIT License
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
|
||||
add_compile_options(
|
||||
-w
|
||||
)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
add_compile_options(
|
||||
/wd4996
|
||||
)
|
||||
endif()
|
||||
|
||||
add_executable(DeprecatedTests
|
||||
add.cpp
|
||||
BasicJsonDocument.cpp
|
||||
containsKey.cpp
|
||||
createNestedArray.cpp
|
||||
createNestedObject.cpp
|
||||
DynamicJsonDocument.cpp
|
||||
macros.cpp
|
||||
memoryUsage.cpp
|
||||
shallowCopy.cpp
|
||||
StaticJsonDocument.cpp
|
||||
)
|
||||
|
||||
add_test(Deprecated DeprecatedTests)
|
||||
|
||||
set_tests_properties(Deprecated
|
||||
PROPERTIES
|
||||
LABELS "Catch"
|
||||
)
|
@ -1,37 +0,0 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
using ArduinoJson::detail::is_base_of;
|
||||
|
||||
TEST_CASE("DynamicJsonDocument") {
|
||||
SECTION("is a JsonDocument") {
|
||||
REQUIRE(is_base_of<JsonDocument, DynamicJsonDocument>::value == true);
|
||||
}
|
||||
|
||||
SECTION("deserialize / serialize") {
|
||||
DynamicJsonDocument doc(256);
|
||||
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||
REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\"}");
|
||||
}
|
||||
|
||||
SECTION("copy") {
|
||||
DynamicJsonDocument doc(256);
|
||||
doc["hello"] = "world";
|
||||
auto copy = doc;
|
||||
REQUIRE(copy.as<std::string>() == "{\"hello\":\"world\"}");
|
||||
}
|
||||
|
||||
SECTION("capacity") {
|
||||
DynamicJsonDocument doc(256);
|
||||
REQUIRE(doc.capacity() == 256);
|
||||
}
|
||||
|
||||
SECTION("garbageCollect()") {
|
||||
DynamicJsonDocument doc(256);
|
||||
doc.garbageCollect();
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
using ArduinoJson::detail::is_base_of;
|
||||
|
||||
TEST_CASE("StaticJsonDocument") {
|
||||
SECTION("is a JsonDocument") {
|
||||
REQUIRE(is_base_of<JsonDocument, StaticJsonDocument<256>>::value == true);
|
||||
}
|
||||
|
||||
SECTION("deserialize / serialize") {
|
||||
StaticJsonDocument<256> doc;
|
||||
deserializeJson(doc, "{\"hello\":\"world\"}");
|
||||
REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\"}");
|
||||
}
|
||||
|
||||
SECTION("copy") {
|
||||
StaticJsonDocument<256> doc;
|
||||
doc["hello"] = "world";
|
||||
auto copy = doc;
|
||||
REQUIRE(copy.as<std::string>() == "{\"hello\":\"world\"}");
|
||||
}
|
||||
|
||||
SECTION("capacity") {
|
||||
StaticJsonDocument<256> doc;
|
||||
REQUIRE(doc.capacity() == 256);
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("JsonArray::add()") {
|
||||
JsonDocument doc;
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
array.add().set(42);
|
||||
REQUIRE(doc.as<std::string>() == "[42]");
|
||||
}
|
||||
|
||||
TEST_CASE("JsonDocument::add()") {
|
||||
JsonDocument doc;
|
||||
doc.add().set(42);
|
||||
REQUIRE(doc.as<std::string>() == "[42]");
|
||||
}
|
||||
|
||||
TEST_CASE("ElementProxy::add()") {
|
||||
JsonDocument doc;
|
||||
doc[0].add().set(42);
|
||||
REQUIRE(doc.as<std::string>() == "[[42]]");
|
||||
}
|
||||
|
||||
TEST_CASE("MemberProxy::add()") {
|
||||
JsonDocument doc;
|
||||
doc["x"].add().set(42);
|
||||
REQUIRE(doc.as<std::string>() == "{\"x\":[42]}");
|
||||
}
|
||||
|
||||
TEST_CASE("JsonVariant::add()") {
|
||||
JsonDocument doc;
|
||||
JsonVariant v = doc.add();
|
||||
v.add().set(42);
|
||||
REQUIRE(doc.as<std::string>() == "[[42]]");
|
||||
}
|
@ -1,210 +0,0 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Literals.hpp"
|
||||
|
||||
TEST_CASE("JsonDocument::containsKey()") {
|
||||
JsonDocument doc;
|
||||
|
||||
SECTION("returns true on object") {
|
||||
doc["hello"] = "world";
|
||||
|
||||
REQUIRE(doc.containsKey("hello") == true);
|
||||
}
|
||||
|
||||
SECTION("returns true when value is null") {
|
||||
doc["hello"] = static_cast<const char*>(0);
|
||||
|
||||
REQUIRE(doc.containsKey("hello") == true);
|
||||
}
|
||||
|
||||
SECTION("returns true when key is a std::string") {
|
||||
doc["hello"] = "world";
|
||||
|
||||
REQUIRE(doc.containsKey("hello"_s) == true);
|
||||
}
|
||||
|
||||
SECTION("returns false on object") {
|
||||
doc["world"] = "hello";
|
||||
|
||||
REQUIRE(doc.containsKey("hello") == false);
|
||||
}
|
||||
|
||||
SECTION("returns false on array") {
|
||||
doc.add("hello");
|
||||
|
||||
REQUIRE(doc.containsKey("hello") == false);
|
||||
}
|
||||
|
||||
SECTION("returns false on null") {
|
||||
REQUIRE(doc.containsKey("hello") == false);
|
||||
}
|
||||
|
||||
SECTION("support JsonVariant") {
|
||||
doc["hello"] = "world";
|
||||
doc["key"] = "hello";
|
||||
|
||||
REQUIRE(doc.containsKey(doc["key"]) == true);
|
||||
REQUIRE(doc.containsKey(doc["foo"]) == false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("MemberProxy::containsKey()") {
|
||||
JsonDocument doc;
|
||||
auto mp = doc["hello"];
|
||||
|
||||
SECTION("containsKey(const char*)") {
|
||||
mp["key"] = "value";
|
||||
|
||||
REQUIRE(mp.containsKey("key") == true);
|
||||
REQUIRE(mp.containsKey("key") == true);
|
||||
}
|
||||
|
||||
SECTION("containsKey(std::string)") {
|
||||
mp["key"] = "value";
|
||||
|
||||
REQUIRE(mp.containsKey("key"_s) == true);
|
||||
REQUIRE(mp.containsKey("key"_s) == true);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonObject::containsKey()") {
|
||||
JsonDocument doc;
|
||||
JsonObject obj = doc.to<JsonObject>();
|
||||
obj["hello"] = 42;
|
||||
|
||||
SECTION("returns true only if key is present") {
|
||||
REQUIRE(false == obj.containsKey("world"));
|
||||
REQUIRE(true == obj.containsKey("hello"));
|
||||
}
|
||||
|
||||
SECTION("returns false after remove()") {
|
||||
obj.remove("hello");
|
||||
|
||||
REQUIRE(false == obj.containsKey("hello"));
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("key is a VLA") {
|
||||
size_t i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "hello");
|
||||
|
||||
REQUIRE(true == obj.containsKey(vla));
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("key is a JsonVariant") {
|
||||
doc["key"] = "hello";
|
||||
REQUIRE(true == obj.containsKey(obj["key"]));
|
||||
REQUIRE(false == obj.containsKey(obj["hello"]));
|
||||
}
|
||||
|
||||
SECTION("std::string") {
|
||||
REQUIRE(true == obj.containsKey("hello"_s));
|
||||
}
|
||||
|
||||
SECTION("unsigned char[]") {
|
||||
unsigned char key[] = "hello";
|
||||
REQUIRE(true == obj.containsKey(key));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonObjectConst::containsKey()") {
|
||||
JsonDocument doc;
|
||||
doc["hello"] = 42;
|
||||
auto obj = doc.as<JsonObjectConst>();
|
||||
|
||||
SECTION("supports const char*") {
|
||||
REQUIRE(false == obj.containsKey("world"));
|
||||
REQUIRE(true == obj.containsKey("hello"));
|
||||
}
|
||||
|
||||
SECTION("supports std::string") {
|
||||
REQUIRE(false == obj.containsKey("world"_s));
|
||||
REQUIRE(true == obj.containsKey("hello"_s));
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("supports VLA") {
|
||||
size_t i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "hello");
|
||||
|
||||
REQUIRE(true == obj.containsKey(vla));
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("supports JsonVariant") {
|
||||
doc["key"] = "hello";
|
||||
REQUIRE(true == obj.containsKey(obj["key"]));
|
||||
REQUIRE(false == obj.containsKey(obj["hello"]));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonVariant::containsKey()") {
|
||||
JsonDocument doc;
|
||||
JsonVariant var = doc.to<JsonVariant>();
|
||||
|
||||
SECTION("returns false is unbound") {
|
||||
CHECK_FALSE(JsonVariant().containsKey("hello"));
|
||||
}
|
||||
|
||||
SECTION("containsKey(const char*)") {
|
||||
var["hello"] = "world";
|
||||
|
||||
REQUIRE(var.containsKey("hello") == true);
|
||||
REQUIRE(var.containsKey("world") == false);
|
||||
}
|
||||
|
||||
SECTION("containsKey(std::string)") {
|
||||
var["hello"] = "world";
|
||||
|
||||
REQUIRE(var.containsKey("hello"_s) == true);
|
||||
REQUIRE(var.containsKey("world"_s) == false);
|
||||
}
|
||||
|
||||
SECTION("containsKey(JsonVariant)") {
|
||||
var["hello"] = "world";
|
||||
var["key"] = "hello";
|
||||
|
||||
REQUIRE(var.containsKey(doc["key"]) == true);
|
||||
REQUIRE(var.containsKey(doc["foo"]) == false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonVariantConst::containsKey()") {
|
||||
JsonDocument doc;
|
||||
doc["hello"] = "world";
|
||||
JsonVariantConst var = doc.as<JsonVariant>();
|
||||
|
||||
SECTION("support const char*") {
|
||||
REQUIRE(var.containsKey("hello") == true);
|
||||
REQUIRE(var.containsKey("world") == false);
|
||||
}
|
||||
|
||||
SECTION("support std::string") {
|
||||
REQUIRE(var.containsKey("hello"_s) == true);
|
||||
REQUIRE(var.containsKey("world"_s) == false);
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("supports VLA") {
|
||||
size_t i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "hello");
|
||||
|
||||
REQUIRE(true == var.containsKey(vla));
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("support JsonVariant") {
|
||||
doc["key"] = "hello";
|
||||
REQUIRE(var.containsKey(var["key"]) == true);
|
||||
REQUIRE(var.containsKey(var["foo"]) == false);
|
||||
}
|
||||
}
|
@ -1,113 +0,0 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Literals.hpp"
|
||||
|
||||
TEST_CASE("JsonDocument::createNestedArray()") {
|
||||
JsonDocument doc;
|
||||
|
||||
SECTION("createNestedArray()") {
|
||||
JsonArray array = doc.createNestedArray();
|
||||
array.add(42);
|
||||
REQUIRE(doc.as<std::string>() == "[[42]]");
|
||||
}
|
||||
|
||||
SECTION("createNestedArray(const char*)") {
|
||||
JsonArray array = doc.createNestedArray("key");
|
||||
array.add(42);
|
||||
REQUIRE(doc.as<std::string>() == "{\"key\":[42]}");
|
||||
}
|
||||
|
||||
SECTION("createNestedArray(std::string)") {
|
||||
JsonArray array = doc.createNestedArray("key"_s);
|
||||
array.add(42);
|
||||
REQUIRE(doc.as<std::string>() == "{\"key\":[42]}");
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("createNestedArray(VLA)") {
|
||||
size_t i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "key");
|
||||
JsonArray array = doc.createNestedArray(vla);
|
||||
array.add(42);
|
||||
REQUIRE(doc.as<std::string>() == "{\"key\":[42]}");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("JsonArray::createNestedArray()") {
|
||||
JsonDocument doc;
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
JsonArray nestedArray = array.createNestedArray();
|
||||
nestedArray.add(42);
|
||||
REQUIRE(doc.as<std::string>() == "[[42]]");
|
||||
}
|
||||
|
||||
TEST_CASE("JsonObject::createNestedArray()") {
|
||||
JsonDocument doc;
|
||||
JsonObject object = doc.to<JsonObject>();
|
||||
|
||||
SECTION("createNestedArray(const char*)") {
|
||||
JsonArray array = object.createNestedArray("key");
|
||||
array.add(42);
|
||||
REQUIRE(doc.as<std::string>() == "{\"key\":[42]}");
|
||||
}
|
||||
|
||||
SECTION("createNestedArray(std::string)") {
|
||||
JsonArray array = object.createNestedArray("key"_s);
|
||||
array.add(42);
|
||||
REQUIRE(doc.as<std::string>() == "{\"key\":[42]}");
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("createNestedArray(VLA)") {
|
||||
size_t i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "key");
|
||||
JsonArray array = object.createNestedArray(vla);
|
||||
array.add(42);
|
||||
REQUIRE(doc.as<std::string>() == "{\"key\":[42]}");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("JsonVariant::createNestedArray()") {
|
||||
JsonDocument doc;
|
||||
JsonVariant variant = doc.to<JsonVariant>();
|
||||
|
||||
SECTION("createNestedArray()") {
|
||||
JsonArray array = variant.createNestedArray();
|
||||
array.add(42);
|
||||
REQUIRE(doc.as<std::string>() == "[[42]]");
|
||||
}
|
||||
|
||||
SECTION("createNestedArray(const char*)") {
|
||||
JsonArray array = variant.createNestedArray("key");
|
||||
array.add(42);
|
||||
REQUIRE(doc.as<std::string>() == "{\"key\":[42]}");
|
||||
}
|
||||
|
||||
SECTION("createNestedArray(std::string)") {
|
||||
JsonArray array = variant.createNestedArray("key"_s);
|
||||
array.add(42);
|
||||
REQUIRE(doc.as<std::string>() == "{\"key\":[42]}");
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("createNestedArray(VLA)") {
|
||||
size_t i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "key");
|
||||
JsonArray array = variant.createNestedArray(vla);
|
||||
array.add(42);
|
||||
REQUIRE(doc.as<std::string>() == "{\"key\":[42]}");
|
||||
}
|
||||
#endif
|
||||
}
|
@ -1,113 +0,0 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Literals.hpp"
|
||||
|
||||
TEST_CASE("JsonDocument::createNestedObject()") {
|
||||
JsonDocument doc;
|
||||
|
||||
SECTION("createNestedObject()") {
|
||||
JsonObject object = doc.createNestedObject();
|
||||
object["hello"] = "world";
|
||||
REQUIRE(doc.as<std::string>() == "[{\"hello\":\"world\"}]");
|
||||
}
|
||||
|
||||
SECTION("createNestedObject(const char*)") {
|
||||
JsonObject object = doc.createNestedObject("key");
|
||||
object["hello"] = "world";
|
||||
REQUIRE(doc.as<std::string>() == "{\"key\":{\"hello\":\"world\"}}");
|
||||
}
|
||||
|
||||
SECTION("createNestedObject(std::string)") {
|
||||
JsonObject object = doc.createNestedObject("key"_s);
|
||||
object["hello"] = "world";
|
||||
REQUIRE(doc.as<std::string>() == "{\"key\":{\"hello\":\"world\"}}");
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("createNestedObject(VLA)") {
|
||||
size_t i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "key");
|
||||
JsonObject object = doc.createNestedObject(vla);
|
||||
object["hello"] = "world";
|
||||
REQUIRE(doc.as<std::string>() == "{\"key\":{\"hello\":\"world\"}}");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("JsonArray::createNestedObject()") {
|
||||
JsonDocument doc;
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
JsonObject object = array.createNestedObject();
|
||||
object["hello"] = "world";
|
||||
REQUIRE(doc.as<std::string>() == "[{\"hello\":\"world\"}]");
|
||||
}
|
||||
|
||||
TEST_CASE("JsonObject::createNestedObject()") {
|
||||
JsonDocument doc;
|
||||
JsonObject object = doc.to<JsonObject>();
|
||||
|
||||
SECTION("createNestedObject(const char*)") {
|
||||
JsonObject nestedObject = object.createNestedObject("key");
|
||||
nestedObject["hello"] = "world";
|
||||
REQUIRE(doc.as<std::string>() == "{\"key\":{\"hello\":\"world\"}}");
|
||||
}
|
||||
|
||||
SECTION("createNestedObject(std::string)") {
|
||||
JsonObject nestedObject = object.createNestedObject("key"_s);
|
||||
nestedObject["hello"] = "world";
|
||||
REQUIRE(doc.as<std::string>() == "{\"key\":{\"hello\":\"world\"}}");
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("createNestedObject(VLA)") {
|
||||
size_t i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "key");
|
||||
JsonObject nestedObject = object.createNestedObject(vla);
|
||||
nestedObject["hello"] = "world";
|
||||
REQUIRE(doc.as<std::string>() == "{\"key\":{\"hello\":\"world\"}}");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST_CASE("JsonVariant::createNestedObject()") {
|
||||
JsonDocument doc;
|
||||
JsonVariant variant = doc.to<JsonVariant>();
|
||||
|
||||
SECTION("createNestedObject()") {
|
||||
JsonObject object = variant.createNestedObject();
|
||||
object["hello"] = "world";
|
||||
REQUIRE(doc.as<std::string>() == "[{\"hello\":\"world\"}]");
|
||||
}
|
||||
|
||||
SECTION("createNestedObject(const char*)") {
|
||||
JsonObject object = variant.createNestedObject("key");
|
||||
object["hello"] = "world";
|
||||
REQUIRE(doc.as<std::string>() == "{\"key\":{\"hello\":\"world\"}}");
|
||||
}
|
||||
|
||||
SECTION("createNestedObject(std::string)") {
|
||||
JsonObject object = variant.createNestedObject("key"_s);
|
||||
object["hello"] = "world";
|
||||
REQUIRE(doc.as<std::string>() == "{\"key\":{\"hello\":\"world\"}}");
|
||||
}
|
||||
|
||||
#ifdef HAS_VARIABLE_LENGTH_ARRAY
|
||||
SECTION("createNestedObject(VLA)") {
|
||||
size_t i = 16;
|
||||
char vla[i];
|
||||
strcpy(vla, "key");
|
||||
JsonObject object = variant.createNestedObject(vla);
|
||||
object["hello"] = "world";
|
||||
REQUIRE(doc.as<std::string>() == "{\"key\":{\"hello\":\"world\"}}");
|
||||
}
|
||||
#endif
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("JSON_ARRAY_SIZE") {
|
||||
REQUIRE(JSON_ARRAY_SIZE(10) == ArduinoJson::detail::sizeofArray(10));
|
||||
}
|
||||
|
||||
TEST_CASE("JSON_OBJECT_SIZE") {
|
||||
REQUIRE(JSON_OBJECT_SIZE(10) == ArduinoJson::detail::sizeofObject(10));
|
||||
}
|
||||
|
||||
TEST_CASE("JSON_STRING_SIZE") {
|
||||
REQUIRE(JSON_STRING_SIZE(10) == 11); // issue #2054
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("JsonArray::memoryUsage()") {
|
||||
JsonArray array;
|
||||
REQUIRE(array.memoryUsage() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("JsonArrayConst::memoryUsage()") {
|
||||
JsonArrayConst array;
|
||||
REQUIRE(array.memoryUsage() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("JsonDocument::memoryUsage()") {
|
||||
JsonDocument doc;
|
||||
REQUIRE(doc.memoryUsage() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("JsonObject::memoryUsage()") {
|
||||
JsonObject array;
|
||||
REQUIRE(array.memoryUsage() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("JsonObjectConst::memoryUsage()") {
|
||||
JsonObjectConst array;
|
||||
REQUIRE(array.memoryUsage() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("JsonVariant::memoryUsage()") {
|
||||
JsonVariant doc;
|
||||
REQUIRE(doc.memoryUsage() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("JsonVariantConst::memoryUsage()") {
|
||||
JsonVariantConst doc;
|
||||
REQUIRE(doc.memoryUsage() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ElementProxy::memoryUsage()") {
|
||||
JsonDocument doc;
|
||||
REQUIRE(doc[0].memoryUsage() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("MemberProxy::memoryUsage()") {
|
||||
JsonDocument doc;
|
||||
REQUIRE(doc["hello"].memoryUsage() == 0);
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("shallowCopy()") {
|
||||
JsonDocument doc1, doc2;
|
||||
doc1["b"] = "c";
|
||||
doc2["a"].shallowCopy(doc1);
|
||||
|
||||
REQUIRE(doc2.as<std::string>() == "{\"a\":{\"b\":\"c\"}}");
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
# ArduinoJson - https://arduinojson.org
|
||||
# Copyright © 2014-2024, Benoit BLANCHON
|
||||
# Copyright © 2014-2023, Benoit BLANCHON
|
||||
# MIT License
|
||||
|
||||
macro(build_should_fail target)
|
||||
@ -23,12 +23,18 @@ endmacro()
|
||||
add_executable(Issue978 Issue978.cpp)
|
||||
build_should_fail(Issue978)
|
||||
|
||||
add_executable(Issue1189 Issue1189.cpp)
|
||||
build_should_fail(Issue1189)
|
||||
|
||||
add_executable(read_long_long read_long_long.cpp)
|
||||
build_should_fail(read_long_long)
|
||||
|
||||
add_executable(write_long_long write_long_long.cpp)
|
||||
build_should_fail(write_long_long)
|
||||
|
||||
add_executable(delete_jsondocument delete_jsondocument.cpp)
|
||||
build_should_fail(delete_jsondocument)
|
||||
|
||||
add_executable(variant_as_char variant_as_char.cpp)
|
||||
build_should_fail(variant_as_char)
|
||||
|
||||
|
13
extras/tests/FailingBuilds/Issue1189.cpp
Normal file
13
extras/tests/FailingBuilds/Issue1189.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
// a function should not be able to get a JsonDocument by value
|
||||
void f(JsonDocument) {}
|
||||
|
||||
int main() {
|
||||
DynamicJsonDocument doc(1024);
|
||||
f(doc);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
@ -8,6 +8,6 @@ struct Stream {};
|
||||
|
||||
int main() {
|
||||
Stream* stream = 0;
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(1024);
|
||||
deserializeJson(doc, stream);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
@ -7,6 +7,6 @@
|
||||
// See issue #1498
|
||||
|
||||
int main() {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(1024);
|
||||
doc["dummy"] = 'A';
|
||||
}
|
||||
|
12
extras/tests/FailingBuilds/delete_jsondocument.cpp
Normal file
12
extras/tests/FailingBuilds/delete_jsondocument.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
struct Stream {};
|
||||
|
||||
int main() {
|
||||
JsonDocument* doc = new DynamicJsonDocument(42);
|
||||
delete doc;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#define ARDUINOJSON_USE_LONG_LONG 0
|
||||
@ -11,6 +11,6 @@
|
||||
|
||||
ARDUINOJSON_ASSERT_INTEGER_TYPE_IS_SUPPORTED(long long)
|
||||
int main() {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(1024);
|
||||
doc["dummy"].as<long long>();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
@ -7,6 +7,6 @@
|
||||
// See issue #1498
|
||||
|
||||
int main() {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(1024);
|
||||
doc["dummy"].as<char>();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#define ARDUINOJSON_USE_LONG_LONG 0
|
||||
@ -10,6 +10,6 @@
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(1024);
|
||||
doc["dummy"] = static_cast<long long>(42);
|
||||
}
|
||||
|
@ -1,288 +0,0 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson/Memory/Allocator.hpp>
|
||||
#include <ArduinoJson/Memory/MemoryPool.hpp>
|
||||
#include <ArduinoJson/Memory/StringBuilder.hpp>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace {
|
||||
|
||||
struct FailingAllocator : ArduinoJson::Allocator {
|
||||
static FailingAllocator* instance() {
|
||||
static FailingAllocator allocator;
|
||||
return &allocator;
|
||||
}
|
||||
|
||||
private:
|
||||
FailingAllocator() = default;
|
||||
~FailingAllocator() = default;
|
||||
|
||||
void* allocate(size_t) override {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void deallocate(void*) override {}
|
||||
|
||||
void* reallocate(void*, size_t) override {
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
class AllocatorLogEntry {
|
||||
public:
|
||||
AllocatorLogEntry(std::string s, size_t n = 1) : str_(s), count_(n) {}
|
||||
|
||||
const std::string& str() const {
|
||||
return str_;
|
||||
}
|
||||
|
||||
size_t count() const {
|
||||
return count_;
|
||||
}
|
||||
|
||||
AllocatorLogEntry operator*(size_t n) const {
|
||||
return AllocatorLogEntry(str_, n);
|
||||
}
|
||||
|
||||
private:
|
||||
std::string str_;
|
||||
size_t count_;
|
||||
};
|
||||
|
||||
inline AllocatorLogEntry Allocate(size_t s) {
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "allocate(%zu)", s);
|
||||
return AllocatorLogEntry(buffer);
|
||||
}
|
||||
|
||||
inline AllocatorLogEntry AllocateFail(size_t s) {
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "allocate(%zu) -> nullptr", s);
|
||||
return AllocatorLogEntry(buffer);
|
||||
}
|
||||
|
||||
inline AllocatorLogEntry Reallocate(size_t s1, size_t s2) {
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "reallocate(%zu, %zu)", s1, s2);
|
||||
return AllocatorLogEntry(buffer);
|
||||
}
|
||||
|
||||
inline AllocatorLogEntry ReallocateFail(size_t s1, size_t s2) {
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "reallocate(%zu, %zu) -> nullptr", s1, s2);
|
||||
return AllocatorLogEntry(buffer);
|
||||
}
|
||||
|
||||
inline AllocatorLogEntry Deallocate(size_t s) {
|
||||
char buffer[32];
|
||||
snprintf(buffer, sizeof(buffer), "deallocate(%zu)", s);
|
||||
return AllocatorLogEntry(buffer);
|
||||
}
|
||||
|
||||
class AllocatorLog {
|
||||
public:
|
||||
AllocatorLog() = default;
|
||||
AllocatorLog(std::initializer_list<AllocatorLogEntry> list) {
|
||||
for (auto& entry : list)
|
||||
append(entry);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
log_.str("");
|
||||
}
|
||||
|
||||
void append(const AllocatorLogEntry& entry) {
|
||||
for (size_t i = 0; i < entry.count(); i++)
|
||||
log_ << entry.str() << "\n";
|
||||
}
|
||||
|
||||
std::string str() const {
|
||||
auto s = log_.str();
|
||||
if (s.empty())
|
||||
return "(empty)";
|
||||
s.pop_back(); // remove the trailing '\n'
|
||||
return s;
|
||||
}
|
||||
|
||||
bool operator==(const AllocatorLog& other) const {
|
||||
return str() == other.str();
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const AllocatorLog& log) {
|
||||
os << log.str();
|
||||
return os;
|
||||
}
|
||||
|
||||
private:
|
||||
std::ostringstream log_;
|
||||
};
|
||||
|
||||
class SpyingAllocator : public ArduinoJson::Allocator {
|
||||
public:
|
||||
SpyingAllocator(
|
||||
Allocator* upstream = ArduinoJson::detail::DefaultAllocator::instance())
|
||||
: upstream_(upstream) {}
|
||||
virtual ~SpyingAllocator() {}
|
||||
|
||||
size_t allocatedBytes() const {
|
||||
return allocatedBytes_;
|
||||
}
|
||||
|
||||
void* allocate(size_t n) override {
|
||||
auto block = reinterpret_cast<AllocatedBlock*>(
|
||||
upstream_->allocate(sizeof(AllocatedBlock) + n - 1));
|
||||
if (block) {
|
||||
log_.append(Allocate(n));
|
||||
allocatedBytes_ += n;
|
||||
block->size = n;
|
||||
return block->payload;
|
||||
} else {
|
||||
log_.append(AllocateFail(n));
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void deallocate(void* p) override {
|
||||
auto block = AllocatedBlock::fromPayload(p);
|
||||
allocatedBytes_ -= block->size;
|
||||
log_.append(Deallocate(block ? block->size : 0));
|
||||
upstream_->deallocate(block);
|
||||
}
|
||||
|
||||
void* reallocate(void* p, size_t n) override {
|
||||
auto block = AllocatedBlock::fromPayload(p);
|
||||
auto oldSize = block ? block->size : 0;
|
||||
block = reinterpret_cast<AllocatedBlock*>(
|
||||
upstream_->reallocate(block, sizeof(AllocatedBlock) + n - 1));
|
||||
if (block) {
|
||||
log_.append(Reallocate(oldSize, n));
|
||||
block->size = n;
|
||||
allocatedBytes_ += n - oldSize;
|
||||
return block->payload;
|
||||
} else {
|
||||
log_.append(ReallocateFail(oldSize, n));
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void clearLog() {
|
||||
log_.clear();
|
||||
}
|
||||
|
||||
const AllocatorLog& log() const {
|
||||
return log_;
|
||||
}
|
||||
|
||||
private:
|
||||
struct AllocatedBlock {
|
||||
size_t size;
|
||||
char payload[1];
|
||||
|
||||
static AllocatedBlock* fromPayload(void* p) {
|
||||
if (!p)
|
||||
return nullptr;
|
||||
return reinterpret_cast<AllocatedBlock*>(
|
||||
// Cast to void* to silence "cast increases required alignment of
|
||||
// target type [-Werror=cast-align]"
|
||||
reinterpret_cast<void*>(reinterpret_cast<char*>(p) -
|
||||
offsetof(AllocatedBlock, payload)));
|
||||
}
|
||||
};
|
||||
|
||||
AllocatorLog log_;
|
||||
Allocator* upstream_;
|
||||
size_t allocatedBytes_ = 0;
|
||||
};
|
||||
|
||||
class KillswitchAllocator : public ArduinoJson::Allocator {
|
||||
public:
|
||||
KillswitchAllocator(
|
||||
Allocator* upstream = ArduinoJson::detail::DefaultAllocator::instance())
|
||||
: working_(true), upstream_(upstream) {}
|
||||
virtual ~KillswitchAllocator() {}
|
||||
|
||||
void* allocate(size_t n) override {
|
||||
return working_ ? upstream_->allocate(n) : 0;
|
||||
}
|
||||
|
||||
void deallocate(void* p) override {
|
||||
upstream_->deallocate(p);
|
||||
}
|
||||
|
||||
void* reallocate(void* ptr, size_t n) override {
|
||||
return working_ ? upstream_->reallocate(ptr, n) : 0;
|
||||
}
|
||||
|
||||
// Turn the killswitch on, so all allocation fail
|
||||
void on() {
|
||||
working_ = false;
|
||||
}
|
||||
|
||||
private:
|
||||
bool working_;
|
||||
Allocator* upstream_;
|
||||
};
|
||||
|
||||
class TimebombAllocator : public ArduinoJson::Allocator {
|
||||
public:
|
||||
TimebombAllocator(
|
||||
size_t initialCountdown,
|
||||
Allocator* upstream = ArduinoJson::detail::DefaultAllocator::instance())
|
||||
: countdown_(initialCountdown), upstream_(upstream) {}
|
||||
virtual ~TimebombAllocator() {}
|
||||
|
||||
void* allocate(size_t n) override {
|
||||
if (!countdown_)
|
||||
return nullptr;
|
||||
countdown_--;
|
||||
return upstream_->allocate(n);
|
||||
}
|
||||
|
||||
void deallocate(void* p) override {
|
||||
upstream_->deallocate(p);
|
||||
}
|
||||
|
||||
void* reallocate(void* ptr, size_t n) override {
|
||||
if (!countdown_)
|
||||
return nullptr;
|
||||
countdown_--;
|
||||
return upstream_->reallocate(ptr, n);
|
||||
}
|
||||
|
||||
void setCountdown(size_t value) {
|
||||
countdown_ = value;
|
||||
}
|
||||
|
||||
private:
|
||||
size_t countdown_ = 0;
|
||||
Allocator* upstream_;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
inline size_t sizeofPoolList(size_t n = ARDUINOJSON_INITIAL_POOL_COUNT) {
|
||||
using namespace ArduinoJson::detail;
|
||||
return sizeof(MemoryPool<VariantData>) * n;
|
||||
}
|
||||
|
||||
inline size_t sizeofPool(
|
||||
ArduinoJson::detail::SlotCount n = ARDUINOJSON_POOL_CAPACITY) {
|
||||
using namespace ArduinoJson::detail;
|
||||
return MemoryPool<VariantData>::slotsToBytes(n);
|
||||
}
|
||||
|
||||
inline size_t sizeofStringBuffer(size_t iteration = 1) {
|
||||
// returns 31, 63, 127, 255, etc.
|
||||
auto capacity = ArduinoJson::detail::StringBuilder::initialCapacity;
|
||||
for (size_t i = 1; i < iteration; i++)
|
||||
capacity = capacity * 2 + 1;
|
||||
return ArduinoJson::detail::sizeofString(capacity);
|
||||
}
|
||||
|
||||
inline size_t sizeofString(const char* s) {
|
||||
return ArduinoJson::detail::sizeofString(strlen(s));
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
@ -1,12 +0,0 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
// the space before _s is required by GCC 4.8
|
||||
inline std::string operator"" _s(const char* str, size_t len) {
|
||||
return std::string(str, len);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
@ -9,14 +9,11 @@
|
||||
// Reproduces Arduino's String class
|
||||
class String {
|
||||
public:
|
||||
String() = default;
|
||||
String(const char* s) {
|
||||
if (s)
|
||||
str_.assign(s);
|
||||
}
|
||||
String() : _maxCapacity(1024) {}
|
||||
explicit String(const char* s) : _str(s), _maxCapacity(1024) {}
|
||||
|
||||
void limitCapacityTo(size_t maxCapacity) {
|
||||
maxCapacity_ = maxCapacity;
|
||||
_maxCapacity = maxCapacity;
|
||||
}
|
||||
|
||||
unsigned char concat(const char* s) {
|
||||
@ -24,48 +21,45 @@ class String {
|
||||
}
|
||||
|
||||
size_t length() const {
|
||||
return str_.size();
|
||||
return _str.size();
|
||||
}
|
||||
|
||||
const char* c_str() const {
|
||||
return str_.c_str();
|
||||
return _str.c_str();
|
||||
}
|
||||
|
||||
bool operator==(const char* s) const {
|
||||
return str_ == s;
|
||||
return _str == s;
|
||||
}
|
||||
|
||||
String& operator=(const char* s) {
|
||||
if (s)
|
||||
str_.assign(s);
|
||||
else
|
||||
str_.clear();
|
||||
_str.assign(s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
char operator[](unsigned int index) const {
|
||||
if (index >= str_.size())
|
||||
if (index >= _str.size())
|
||||
return 0;
|
||||
return str_[index];
|
||||
return _str[index];
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& lhs, const ::String& rhs) {
|
||||
lhs << rhs.str_;
|
||||
lhs << rhs._str;
|
||||
return lhs;
|
||||
}
|
||||
|
||||
protected:
|
||||
// This function is protected in most Arduino cores
|
||||
unsigned char concat(const char* s, size_t n) {
|
||||
if (str_.size() + n > maxCapacity_)
|
||||
if (_str.size() + n > _maxCapacity)
|
||||
return 0;
|
||||
str_.append(s, n);
|
||||
_str.append(s, n);
|
||||
return 1;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string str_;
|
||||
size_t maxCapacity_ = 1024;
|
||||
std::string _str;
|
||||
size_t _maxCapacity;
|
||||
};
|
||||
|
||||
class StringSumHelper : public ::String {};
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#pragma once
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ArduinoJson - https://arduinojson.org
|
||||
# Copyright © 2014-2024, Benoit BLANCHON
|
||||
# Copyright © 2014-2023, Benoit BLANCHON
|
||||
# MIT License
|
||||
|
||||
add_executable(IntegrationTests
|
||||
|
@ -1,12 +1,12 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("Gbathree") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
|
||||
DeserializationError error = deserializeJson(
|
||||
doc,
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
@ -8,8 +8,8 @@
|
||||
// https://github.com/bblanchon/ArduinoJson/issues/772
|
||||
|
||||
TEST_CASE("Issue772") {
|
||||
JsonDocument doc1;
|
||||
JsonDocument doc2;
|
||||
DynamicJsonDocument doc1(4096);
|
||||
DynamicJsonDocument doc2(4096);
|
||||
DeserializationError err;
|
||||
std::string data =
|
||||
"{\"state\":{\"reported\":{\"timestamp\":\"2018-07-02T09:40:12Z\","
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
@ -53,12 +53,12 @@ TEST_CASE("OpenWeatherMap") {
|
||||
"]}";
|
||||
// clang-format on
|
||||
|
||||
JsonDocument filter;
|
||||
StaticJsonDocument<512> filter;
|
||||
filter["list"][0]["dt"] = true;
|
||||
filter["list"][0]["main"]["temp"] = true;
|
||||
filter["list"][0]["weather"][0]["description"] = true;
|
||||
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(16384);
|
||||
|
||||
REQUIRE(
|
||||
deserializeJson(doc, input_json, DeserializationOption::Filter(filter)) ==
|
||||
|
@ -1,12 +1,12 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
void check(std::string originalJson) {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(16384);
|
||||
|
||||
std::string prettyJson;
|
||||
deserializeJson(doc, originalJson);
|
||||
|
@ -1,5 +1,5 @@
|
||||
# ArduinoJson - https://arduinojson.org
|
||||
# Copyright © 2014-2024, Benoit BLANCHON
|
||||
# Copyright © 2014-2023, Benoit BLANCHON
|
||||
# MIT License
|
||||
|
||||
add_executable(JsonArrayTests
|
||||
@ -7,9 +7,11 @@ add_executable(JsonArrayTests
|
||||
clear.cpp
|
||||
compare.cpp
|
||||
copyArray.cpp
|
||||
createNested.cpp
|
||||
equals.cpp
|
||||
isNull.cpp
|
||||
iterator.cpp
|
||||
memoryUsage.cpp
|
||||
nesting.cpp
|
||||
remove.cpp
|
||||
size.cpp
|
||||
|
@ -1,18 +1,12 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
#include "Literals.hpp"
|
||||
|
||||
using ArduinoJson::detail::sizeofArray;
|
||||
|
||||
TEST_CASE("JsonArray::add(T)") {
|
||||
SpyingAllocator spy;
|
||||
JsonDocument doc(&spy);
|
||||
TEST_CASE("JsonArray::add()") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
|
||||
SECTION("int") {
|
||||
@ -52,12 +46,12 @@ TEST_CASE("JsonArray::add(T)") {
|
||||
|
||||
array.add(vla);
|
||||
|
||||
REQUIRE("world"_s == array[0]);
|
||||
REQUIRE(std::string("world") == array[0]);
|
||||
}
|
||||
#endif
|
||||
|
||||
SECTION("nested array") {
|
||||
JsonDocument doc2;
|
||||
DynamicJsonDocument doc2(4096);
|
||||
JsonArray arr = doc2.to<JsonArray>();
|
||||
|
||||
array.add(arr);
|
||||
@ -68,7 +62,7 @@ TEST_CASE("JsonArray::add(T)") {
|
||||
}
|
||||
|
||||
SECTION("nested object") {
|
||||
JsonDocument doc2;
|
||||
DynamicJsonDocument doc2(4096);
|
||||
JsonObject obj = doc2.to<JsonObject>();
|
||||
|
||||
array.add(obj);
|
||||
@ -80,7 +74,7 @@ TEST_CASE("JsonArray::add(T)") {
|
||||
|
||||
SECTION("array subscript") {
|
||||
const char* str = "hello";
|
||||
JsonDocument doc2;
|
||||
DynamicJsonDocument doc2(4096);
|
||||
JsonArray arr = doc2.to<JsonArray>();
|
||||
arr.add(str);
|
||||
|
||||
@ -91,7 +85,7 @@ TEST_CASE("JsonArray::add(T)") {
|
||||
|
||||
SECTION("object subscript") {
|
||||
const char* str = "hello";
|
||||
JsonDocument doc2;
|
||||
DynamicJsonDocument doc2(4096);
|
||||
JsonObject obj = doc2.to<JsonObject>();
|
||||
obj["x"] = str;
|
||||
|
||||
@ -102,130 +96,43 @@ TEST_CASE("JsonArray::add(T)") {
|
||||
|
||||
SECTION("should not duplicate const char*") {
|
||||
array.add("world");
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
});
|
||||
const size_t expectedSize = JSON_ARRAY_SIZE(1);
|
||||
REQUIRE(expectedSize == doc.memoryUsage());
|
||||
}
|
||||
|
||||
SECTION("should duplicate char*") {
|
||||
array.add(const_cast<char*>("world"));
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
Allocate(sizeofString("world")),
|
||||
});
|
||||
const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(5);
|
||||
REQUIRE(expectedSize == doc.memoryUsage());
|
||||
}
|
||||
|
||||
SECTION("should duplicate std::string") {
|
||||
array.add("world"_s);
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
Allocate(sizeofString("world")),
|
||||
});
|
||||
array.add(std::string("world"));
|
||||
const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(5);
|
||||
REQUIRE(expectedSize == doc.memoryUsage());
|
||||
}
|
||||
|
||||
SECTION("should duplicate serialized(const char*)") {
|
||||
SECTION("should not duplicate serialized(const char*)") {
|
||||
array.add(serialized("{}"));
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
Allocate(sizeofString("{}")),
|
||||
});
|
||||
const size_t expectedSize = JSON_ARRAY_SIZE(1);
|
||||
REQUIRE(expectedSize == doc.memoryUsage());
|
||||
}
|
||||
|
||||
SECTION("should duplicate serialized(char*)") {
|
||||
array.add(serialized(const_cast<char*>("{}")));
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
Allocate(sizeofString("{}")),
|
||||
});
|
||||
const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(2);
|
||||
REQUIRE(expectedSize == doc.memoryUsage());
|
||||
}
|
||||
|
||||
SECTION("should duplicate serialized(std::string)") {
|
||||
array.add(serialized("{}"_s));
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
Allocate(sizeofString("{}")),
|
||||
});
|
||||
array.add(serialized(std::string("{}")));
|
||||
const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(2);
|
||||
REQUIRE(expectedSize == doc.memoryUsage());
|
||||
}
|
||||
|
||||
SECTION("should duplicate serialized(std::string)") {
|
||||
array.add(serialized("\0XX"_s));
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
Allocate(sizeofString(" XX")),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonArray::add<T>()") {
|
||||
JsonDocument doc;
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
|
||||
SECTION("add<JsonArray>()") {
|
||||
JsonArray nestedArray = array.add<JsonArray>();
|
||||
nestedArray.add(1);
|
||||
nestedArray.add(2);
|
||||
REQUIRE(doc.as<std::string>() == "[[1,2]]");
|
||||
}
|
||||
|
||||
SECTION("add<JsonObject>()") {
|
||||
JsonObject nestedObject = array.add<JsonObject>();
|
||||
nestedObject["a"] = 1;
|
||||
nestedObject["b"] = 2;
|
||||
REQUIRE(doc.as<std::string>() == "[{\"a\":1,\"b\":2}]");
|
||||
}
|
||||
|
||||
SECTION("add<JsonVariant>()") {
|
||||
JsonVariant nestedVariant = array.add<JsonVariant>();
|
||||
nestedVariant.set(42);
|
||||
REQUIRE(doc.as<std::string>() == "[42]");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonObject::add(JsonObject) ") {
|
||||
JsonDocument doc1;
|
||||
doc1["key1"_s] = "value1"_s;
|
||||
|
||||
TimebombAllocator allocator(10);
|
||||
SpyingAllocator spy(&allocator);
|
||||
JsonDocument doc2(&spy);
|
||||
JsonArray array = doc2.to<JsonArray>();
|
||||
|
||||
SECTION("success") {
|
||||
bool result = array.add(doc1.as<JsonObject>());
|
||||
|
||||
REQUIRE(result == true);
|
||||
REQUIRE(doc2.as<std::string>() == "[{\"key1\":\"value1\"}]");
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
Allocate(sizeofString("key1")),
|
||||
Allocate(sizeofString("value1")),
|
||||
});
|
||||
}
|
||||
|
||||
SECTION("partial failure") { // issue #2081
|
||||
allocator.setCountdown(2);
|
||||
|
||||
bool result = array.add(doc1.as<JsonObject>());
|
||||
|
||||
REQUIRE(result == false);
|
||||
REQUIRE(doc2.as<std::string>() == "[]");
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
Allocate(sizeofString("key1")),
|
||||
AllocateFail(sizeofString("value1")),
|
||||
Deallocate(sizeofString("key1")),
|
||||
});
|
||||
}
|
||||
|
||||
SECTION("complete failure") {
|
||||
allocator.setCountdown(0);
|
||||
|
||||
bool result = array.add(doc1.as<JsonObject>());
|
||||
|
||||
REQUIRE(result == false);
|
||||
REQUIRE(doc2.as<std::string>() == "[]");
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
AllocateFail(sizeofPool()),
|
||||
});
|
||||
array.add(serialized(std::string("\0XX", 3)));
|
||||
const size_t expectedSize = JSON_ARRAY_SIZE(1) + JSON_STRING_SIZE(3);
|
||||
REQUIRE(expectedSize == doc.memoryUsage());
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,10 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
|
||||
TEST_CASE("JsonArray::clear()") {
|
||||
SECTION("No-op on null JsonArray") {
|
||||
JsonArray array;
|
||||
@ -16,7 +14,7 @@ TEST_CASE("JsonArray::clear()") {
|
||||
}
|
||||
|
||||
SECTION("Removes all elements") {
|
||||
JsonDocument doc;
|
||||
StaticJsonDocument<64> doc;
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
array.add(1);
|
||||
array.add(2);
|
||||
@ -24,23 +22,4 @@ TEST_CASE("JsonArray::clear()") {
|
||||
REQUIRE(array.size() == 0);
|
||||
REQUIRE(array.isNull() == false);
|
||||
}
|
||||
|
||||
SECTION("Removed elements are recycled") {
|
||||
SpyingAllocator spy;
|
||||
JsonDocument doc(&spy);
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
|
||||
// fill the pool entirely
|
||||
for (int i = 0; i < ARDUINOJSON_POOL_CAPACITY; i++)
|
||||
array.add(i);
|
||||
|
||||
// clear and fill again
|
||||
array.clear();
|
||||
for (int i = 0; i < ARDUINOJSON_POOL_CAPACITY; i++)
|
||||
array.add(i);
|
||||
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Allocate(sizeofPool()),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("Compare JsonArray with JsonArray") {
|
||||
JsonDocument doc;
|
||||
StaticJsonDocument<256> doc;
|
||||
|
||||
SECTION("Compare with unbound") {
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
@ -43,15 +43,15 @@ TEST_CASE("Compare JsonArray with JsonArray") {
|
||||
}
|
||||
|
||||
SECTION("Compare with identical array") {
|
||||
JsonArray array1 = doc.add<JsonArray>();
|
||||
JsonArray array1 = doc.createNestedArray();
|
||||
array1.add(1);
|
||||
array1.add("hello");
|
||||
array1.add<JsonObject>();
|
||||
array1.createNestedObject();
|
||||
|
||||
JsonArray array2 = doc.add<JsonArray>();
|
||||
JsonArray array2 = doc.createNestedArray();
|
||||
array2.add(1);
|
||||
array2.add("hello");
|
||||
array2.add<JsonObject>();
|
||||
array2.createNestedObject();
|
||||
|
||||
CHECK(array1 == array2);
|
||||
CHECK(array1 <= array2);
|
||||
@ -62,15 +62,15 @@ TEST_CASE("Compare JsonArray with JsonArray") {
|
||||
}
|
||||
|
||||
SECTION("Compare with different array") {
|
||||
JsonArray array1 = doc.add<JsonArray>();
|
||||
JsonArray array1 = doc.createNestedArray();
|
||||
array1.add(1);
|
||||
array1.add("hello1");
|
||||
array1.add<JsonObject>();
|
||||
array1.createNestedObject();
|
||||
|
||||
JsonArray array2 = doc.add<JsonArray>();
|
||||
JsonArray array2 = doc.createNestedArray();
|
||||
array2.add(1);
|
||||
array2.add("hello2");
|
||||
array2.add<JsonObject>();
|
||||
array2.createNestedObject();
|
||||
|
||||
CHECK(array1 != array2);
|
||||
CHECK_FALSE(array1 == array2);
|
||||
@ -82,7 +82,7 @@ TEST_CASE("Compare JsonArray with JsonArray") {
|
||||
}
|
||||
|
||||
TEST_CASE("Compare JsonArray with JsonVariant") {
|
||||
JsonDocument doc;
|
||||
StaticJsonDocument<256> doc;
|
||||
|
||||
SECTION("Compare with self") {
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
@ -107,15 +107,15 @@ TEST_CASE("Compare JsonArray with JsonVariant") {
|
||||
}
|
||||
|
||||
SECTION("Compare with identical array") {
|
||||
JsonArray array = doc.add<JsonArray>();
|
||||
JsonArray array = doc.createNestedArray();
|
||||
array.add(1);
|
||||
array.add("hello");
|
||||
array.add<JsonObject>();
|
||||
array.createNestedObject();
|
||||
|
||||
JsonVariant variant = doc.add<JsonArray>();
|
||||
JsonVariant variant = doc.createNestedArray();
|
||||
variant.add(1);
|
||||
variant.add("hello");
|
||||
variant.add<JsonObject>();
|
||||
variant.createNestedObject();
|
||||
|
||||
CHECK(array == variant);
|
||||
CHECK(array <= variant);
|
||||
@ -133,15 +133,15 @@ TEST_CASE("Compare JsonArray with JsonVariant") {
|
||||
}
|
||||
|
||||
SECTION("Compare with different array") {
|
||||
JsonArray array = doc.add<JsonArray>();
|
||||
JsonArray array = doc.createNestedArray();
|
||||
array.add(1);
|
||||
array.add("hello1");
|
||||
array.add<JsonObject>();
|
||||
array.createNestedObject();
|
||||
|
||||
JsonVariant variant = doc.add<JsonArray>();
|
||||
JsonVariant variant = doc.createNestedArray();
|
||||
variant.add(1);
|
||||
variant.add("hello2");
|
||||
variant.add<JsonObject>();
|
||||
variant.createNestedObject();
|
||||
|
||||
CHECK(array != variant);
|
||||
CHECK_FALSE(array == variant);
|
||||
@ -153,7 +153,7 @@ TEST_CASE("Compare JsonArray with JsonVariant") {
|
||||
}
|
||||
|
||||
TEST_CASE("Compare JsonArray with JsonVariantConst") {
|
||||
JsonDocument doc;
|
||||
StaticJsonDocument<256> doc;
|
||||
|
||||
SECTION("Compare with unbound") {
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
@ -199,15 +199,15 @@ TEST_CASE("Compare JsonArray with JsonVariantConst") {
|
||||
}
|
||||
|
||||
SECTION("Compare with identical array") {
|
||||
JsonArray array = doc.add<JsonArray>();
|
||||
JsonArray array = doc.createNestedArray();
|
||||
array.add(1);
|
||||
array.add("hello");
|
||||
array.add<JsonObject>();
|
||||
array.createNestedObject();
|
||||
|
||||
JsonArray array2 = doc.add<JsonArray>();
|
||||
JsonArray array2 = doc.createNestedArray();
|
||||
array2.add(1);
|
||||
array2.add("hello");
|
||||
array2.add<JsonObject>();
|
||||
array2.createNestedObject();
|
||||
JsonVariantConst variant = array2;
|
||||
|
||||
CHECK(array == variant);
|
||||
@ -226,15 +226,15 @@ TEST_CASE("Compare JsonArray with JsonVariantConst") {
|
||||
}
|
||||
|
||||
SECTION("Compare with different array") {
|
||||
JsonArray array = doc.add<JsonArray>();
|
||||
JsonArray array = doc.createNestedArray();
|
||||
array.add(1);
|
||||
array.add("hello1");
|
||||
array.add<JsonObject>();
|
||||
array.createNestedObject();
|
||||
|
||||
JsonArray array2 = doc.add<JsonArray>();
|
||||
JsonArray array2 = doc.createNestedArray();
|
||||
array2.add(1);
|
||||
array2.add("hello2");
|
||||
array2.add<JsonObject>();
|
||||
array2.createNestedObject();
|
||||
JsonVariantConst variant = array2;
|
||||
|
||||
CHECK(array != variant);
|
||||
@ -247,7 +247,7 @@ TEST_CASE("Compare JsonArray with JsonVariantConst") {
|
||||
}
|
||||
|
||||
TEST_CASE("Compare JsonArray with JsonArrayConst") {
|
||||
JsonDocument doc;
|
||||
StaticJsonDocument<256> doc;
|
||||
|
||||
SECTION("Compare with unbound") {
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
@ -292,15 +292,15 @@ TEST_CASE("Compare JsonArray with JsonArrayConst") {
|
||||
}
|
||||
|
||||
SECTION("Compare with identical array") {
|
||||
JsonArray array1 = doc.add<JsonArray>();
|
||||
JsonArray array1 = doc.createNestedArray();
|
||||
array1.add(1);
|
||||
array1.add("hello");
|
||||
array1.add<JsonObject>();
|
||||
array1.createNestedObject();
|
||||
|
||||
JsonArray array2 = doc.add<JsonArray>();
|
||||
JsonArray array2 = doc.createNestedArray();
|
||||
array2.add(1);
|
||||
array2.add("hello");
|
||||
array2.add<JsonObject>();
|
||||
array2.createNestedObject();
|
||||
JsonArrayConst carray2 = array2;
|
||||
|
||||
CHECK(array1 == carray2);
|
||||
@ -319,15 +319,15 @@ TEST_CASE("Compare JsonArray with JsonArrayConst") {
|
||||
}
|
||||
|
||||
SECTION("Compare with different array") {
|
||||
JsonArray array1 = doc.add<JsonArray>();
|
||||
JsonArray array1 = doc.createNestedArray();
|
||||
array1.add(1);
|
||||
array1.add("hello1");
|
||||
array1.add<JsonObject>();
|
||||
array1.createNestedObject();
|
||||
|
||||
JsonArray array2 = doc.add<JsonArray>();
|
||||
JsonArray array2 = doc.createNestedArray();
|
||||
array2.add(1);
|
||||
array2.add("hello2");
|
||||
array2.add<JsonObject>();
|
||||
array2.createNestedObject();
|
||||
JsonArrayConst carray2 = array2;
|
||||
|
||||
CHECK(array1 != carray2);
|
||||
@ -347,7 +347,7 @@ TEST_CASE("Compare JsonArray with JsonArrayConst") {
|
||||
}
|
||||
|
||||
TEST_CASE("Compare JsonArrayConst with JsonArrayConst") {
|
||||
JsonDocument doc;
|
||||
StaticJsonDocument<256> doc;
|
||||
|
||||
SECTION("Compare with unbound") {
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
@ -387,16 +387,16 @@ TEST_CASE("Compare JsonArrayConst with JsonArrayConst") {
|
||||
}
|
||||
|
||||
SECTION("Compare with identical array") {
|
||||
JsonArray array1 = doc.add<JsonArray>();
|
||||
JsonArray array1 = doc.createNestedArray();
|
||||
array1.add(1);
|
||||
array1.add("hello");
|
||||
array1.add<JsonObject>();
|
||||
array1.createNestedObject();
|
||||
JsonArrayConst carray1 = array1;
|
||||
|
||||
JsonArray array2 = doc.add<JsonArray>();
|
||||
JsonArray array2 = doc.createNestedArray();
|
||||
array2.add(1);
|
||||
array2.add("hello");
|
||||
array2.add<JsonObject>();
|
||||
array2.createNestedObject();
|
||||
JsonArrayConst carray2 = array2;
|
||||
|
||||
CHECK(carray1 == carray2);
|
||||
@ -408,16 +408,16 @@ TEST_CASE("Compare JsonArrayConst with JsonArrayConst") {
|
||||
}
|
||||
|
||||
SECTION("Compare with different array") {
|
||||
JsonArray array1 = doc.add<JsonArray>();
|
||||
JsonArray array1 = doc.createNestedArray();
|
||||
array1.add(1);
|
||||
array1.add("hello1");
|
||||
array1.add<JsonObject>();
|
||||
array1.createNestedObject();
|
||||
JsonArrayConst carray1 = array1;
|
||||
|
||||
JsonArray array2 = doc.add<JsonArray>();
|
||||
JsonArray array2 = doc.createNestedArray();
|
||||
array2.add(1);
|
||||
array2.add("hello2");
|
||||
array2.add<JsonObject>();
|
||||
array2.createNestedObject();
|
||||
JsonArrayConst carray2 = array2;
|
||||
|
||||
CHECK(carray1 != carray2);
|
||||
@ -430,7 +430,7 @@ TEST_CASE("Compare JsonArrayConst with JsonArrayConst") {
|
||||
}
|
||||
|
||||
TEST_CASE("Compare JsonArrayConst with JsonVariant") {
|
||||
JsonDocument doc;
|
||||
StaticJsonDocument<256> doc;
|
||||
|
||||
SECTION("Compare with self") {
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
@ -455,16 +455,16 @@ TEST_CASE("Compare JsonArrayConst with JsonVariant") {
|
||||
}
|
||||
|
||||
SECTION("Compare with identical array") {
|
||||
JsonArray array1 = doc.add<JsonArray>();
|
||||
JsonArray array1 = doc.createNestedArray();
|
||||
array1.add(1);
|
||||
array1.add("hello");
|
||||
array1.add<JsonObject>();
|
||||
array1.createNestedObject();
|
||||
JsonArrayConst carray1 = array1;
|
||||
|
||||
JsonArray array2 = doc.add<JsonArray>();
|
||||
JsonArray array2 = doc.createNestedArray();
|
||||
array2.add(1);
|
||||
array2.add("hello");
|
||||
array2.add<JsonObject>();
|
||||
array2.createNestedObject();
|
||||
JsonVariant variant2 = array2;
|
||||
|
||||
CHECK(carray1 == variant2);
|
||||
@ -483,16 +483,16 @@ TEST_CASE("Compare JsonArrayConst with JsonVariant") {
|
||||
}
|
||||
|
||||
SECTION("Compare with different array") {
|
||||
JsonArray array1 = doc.add<JsonArray>();
|
||||
JsonArray array1 = doc.createNestedArray();
|
||||
array1.add(1);
|
||||
array1.add("hello1");
|
||||
array1.add<JsonObject>();
|
||||
array1.createNestedObject();
|
||||
JsonArrayConst carray1 = array1;
|
||||
|
||||
JsonArray array2 = doc.add<JsonArray>();
|
||||
JsonArray array2 = doc.createNestedArray();
|
||||
array2.add(1);
|
||||
array2.add("hello2");
|
||||
array2.add<JsonObject>();
|
||||
array2.createNestedObject();
|
||||
JsonVariant variant2 = array2;
|
||||
|
||||
CHECK(carray1 != variant2);
|
||||
|
@ -1,16 +1,13 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
#include "Allocators.hpp"
|
||||
#include "Literals.hpp"
|
||||
|
||||
TEST_CASE("copyArray()") {
|
||||
SECTION("int[] -> JsonArray") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
char json[32];
|
||||
int source[] = {1, 2, 3};
|
||||
@ -19,11 +16,11 @@ TEST_CASE("copyArray()") {
|
||||
CHECK(ok);
|
||||
|
||||
serializeJson(array, json);
|
||||
CHECK("[1,2,3]"_s == json);
|
||||
CHECK(std::string("[1,2,3]") == json);
|
||||
}
|
||||
|
||||
SECTION("std::string[] -> JsonArray") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
char json[32];
|
||||
std::string source[] = {"a", "b", "c"};
|
||||
@ -32,11 +29,11 @@ TEST_CASE("copyArray()") {
|
||||
CHECK(ok);
|
||||
|
||||
serializeJson(array, json);
|
||||
CHECK("[\"a\",\"b\",\"c\"]"_s == json);
|
||||
CHECK(std::string("[\"a\",\"b\",\"c\"]") == json);
|
||||
}
|
||||
|
||||
SECTION("const char*[] -> JsonArray") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
char json[32];
|
||||
const char* source[] = {"a", "b", "c"};
|
||||
@ -45,11 +42,11 @@ TEST_CASE("copyArray()") {
|
||||
CHECK(ok);
|
||||
|
||||
serializeJson(array, json);
|
||||
CHECK("[\"a\",\"b\",\"c\"]"_s == json);
|
||||
CHECK(std::string("[\"a\",\"b\",\"c\"]") == json);
|
||||
}
|
||||
|
||||
SECTION("const char[][] -> JsonArray") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
char json[32];
|
||||
char source[][2] = {"a", "b", "c"};
|
||||
@ -58,11 +55,11 @@ TEST_CASE("copyArray()") {
|
||||
CHECK(ok);
|
||||
|
||||
serializeJson(array, json);
|
||||
CHECK("[\"a\",\"b\",\"c\"]"_s == json);
|
||||
CHECK(std::string("[\"a\",\"b\",\"c\"]") == json);
|
||||
}
|
||||
|
||||
SECTION("const char[][] -> JsonDocument") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[32];
|
||||
char source[][2] = {"a", "b", "c"};
|
||||
|
||||
@ -70,11 +67,11 @@ TEST_CASE("copyArray()") {
|
||||
CHECK(ok);
|
||||
|
||||
serializeJson(doc, json);
|
||||
CHECK("[\"a\",\"b\",\"c\"]"_s == json);
|
||||
CHECK(std::string("[\"a\",\"b\",\"c\"]") == json);
|
||||
}
|
||||
|
||||
SECTION("const char[][] -> MemberProxy") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[32];
|
||||
char source[][2] = {"a", "b", "c"};
|
||||
|
||||
@ -82,11 +79,11 @@ TEST_CASE("copyArray()") {
|
||||
CHECK(ok);
|
||||
|
||||
serializeJson(doc, json);
|
||||
CHECK("{\"data\":[\"a\",\"b\",\"c\"]}"_s == json);
|
||||
CHECK(std::string("{\"data\":[\"a\",\"b\",\"c\"]}") == json);
|
||||
}
|
||||
|
||||
SECTION("int[] -> JsonDocument") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[32];
|
||||
int source[] = {1, 2, 3};
|
||||
|
||||
@ -94,11 +91,11 @@ TEST_CASE("copyArray()") {
|
||||
CHECK(ok);
|
||||
|
||||
serializeJson(doc, json);
|
||||
CHECK("[1,2,3]"_s == json);
|
||||
CHECK(std::string("[1,2,3]") == json);
|
||||
}
|
||||
|
||||
SECTION("int[] -> MemberProxy") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[32];
|
||||
int source[] = {1, 2, 3};
|
||||
|
||||
@ -106,20 +103,25 @@ TEST_CASE("copyArray()") {
|
||||
CHECK(ok);
|
||||
|
||||
serializeJson(doc, json);
|
||||
CHECK("{\"data\":[1,2,3]}"_s == json);
|
||||
CHECK(std::string("{\"data\":[1,2,3]}") == json);
|
||||
}
|
||||
|
||||
SECTION("int[] -> JsonArray, but not enough memory") {
|
||||
JsonDocument doc(FailingAllocator::instance());
|
||||
const size_t SIZE = JSON_ARRAY_SIZE(2);
|
||||
StaticJsonDocument<SIZE> doc;
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
char json[32];
|
||||
int source[] = {1, 2, 3};
|
||||
|
||||
bool ok = copyArray(source, array);
|
||||
REQUIRE_FALSE(ok);
|
||||
|
||||
serializeJson(array, json);
|
||||
CHECK(std::string("[1,2]") == json);
|
||||
}
|
||||
|
||||
SECTION("int[][] -> JsonArray") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
char json[32];
|
||||
int source[][3] = {{1, 2, 3}, {4, 5, 6}};
|
||||
@ -128,11 +130,11 @@ TEST_CASE("copyArray()") {
|
||||
CHECK(ok);
|
||||
|
||||
serializeJson(array, json);
|
||||
CHECK("[[1,2,3],[4,5,6]]"_s == json);
|
||||
CHECK(std::string("[[1,2,3],[4,5,6]]") == json);
|
||||
}
|
||||
|
||||
SECTION("int[][] -> MemberProxy") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[32];
|
||||
int source[][3] = {{1, 2, 3}, {4, 5, 6}};
|
||||
|
||||
@ -140,11 +142,11 @@ TEST_CASE("copyArray()") {
|
||||
CHECK(ok);
|
||||
|
||||
serializeJson(doc, json);
|
||||
CHECK("{\"data\":[[1,2,3],[4,5,6]]}"_s == json);
|
||||
CHECK(std::string("{\"data\":[[1,2,3],[4,5,6]]}") == json);
|
||||
}
|
||||
|
||||
SECTION("int[][] -> JsonDocument") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[32];
|
||||
int source[][3] = {{1, 2, 3}, {4, 5, 6}};
|
||||
|
||||
@ -152,20 +154,29 @@ TEST_CASE("copyArray()") {
|
||||
CHECK(ok);
|
||||
|
||||
serializeJson(doc, json);
|
||||
CHECK("[[1,2,3],[4,5,6]]"_s == json);
|
||||
CHECK(std::string("[[1,2,3],[4,5,6]]") == json);
|
||||
}
|
||||
|
||||
SECTION("int[][] -> JsonArray, but not enough memory") {
|
||||
JsonDocument doc(FailingAllocator::instance());
|
||||
const size_t SIZE =
|
||||
JSON_ARRAY_SIZE(2) + JSON_ARRAY_SIZE(3) + JSON_ARRAY_SIZE(2);
|
||||
StaticJsonDocument<SIZE> doc;
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
char json[32] = "";
|
||||
int source[][3] = {{1, 2, 3}, {4, 5, 6}};
|
||||
|
||||
CAPTURE(SIZE);
|
||||
|
||||
bool ok = copyArray(source, array);
|
||||
REQUIRE(ok == false);
|
||||
CAPTURE(doc.memoryUsage());
|
||||
CHECK_FALSE(ok);
|
||||
|
||||
serializeJson(array, json);
|
||||
CHECK(std::string("[[1,2,3],[4,5]]") == json);
|
||||
}
|
||||
|
||||
SECTION("JsonArray -> int[], with more space than needed") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[] = "[1,2,3]";
|
||||
DeserializationError err = deserializeJson(doc, json);
|
||||
CHECK(err == DeserializationError::Ok);
|
||||
@ -182,7 +193,7 @@ TEST_CASE("copyArray()") {
|
||||
}
|
||||
|
||||
SECTION("JsonArray -> int[], without enough space") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[] = "[1,2,3]";
|
||||
DeserializationError err = deserializeJson(doc, json);
|
||||
CHECK(err == DeserializationError::Ok);
|
||||
@ -197,7 +208,7 @@ TEST_CASE("copyArray()") {
|
||||
}
|
||||
|
||||
SECTION("JsonArray -> std::string[]") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[] = "[\"a\",\"b\",\"c\"]";
|
||||
DeserializationError err = deserializeJson(doc, json);
|
||||
CHECK(err == DeserializationError::Ok);
|
||||
@ -214,7 +225,7 @@ TEST_CASE("copyArray()") {
|
||||
}
|
||||
|
||||
SECTION("JsonArray -> char[N][]") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[] = "[\"a12345\",\"b123456\",\"c1234567\"]";
|
||||
DeserializationError err = deserializeJson(doc, json);
|
||||
CHECK(err == DeserializationError::Ok);
|
||||
@ -224,14 +235,14 @@ TEST_CASE("copyArray()") {
|
||||
size_t result = copyArray(array, destination);
|
||||
|
||||
CHECK(3 == result);
|
||||
CHECK("a12345"_s == destination[0]);
|
||||
CHECK("b123456"_s == destination[1]);
|
||||
CHECK("c123456"_s == destination[2]); // truncated
|
||||
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[]") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[] = "[1,2,3]";
|
||||
DeserializationError err = deserializeJson(doc, json);
|
||||
CHECK(err == DeserializationError::Ok);
|
||||
@ -247,7 +258,7 @@ TEST_CASE("copyArray()") {
|
||||
}
|
||||
|
||||
SECTION("MemberProxy -> int[]") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[] = "{\"data\":[1,2,3]}";
|
||||
DeserializationError err = deserializeJson(doc, json);
|
||||
CHECK(err == DeserializationError::Ok);
|
||||
@ -263,7 +274,7 @@ TEST_CASE("copyArray()") {
|
||||
}
|
||||
|
||||
SECTION("ElementProxy -> int[]") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[] = "[[1,2,3]]";
|
||||
DeserializationError err = deserializeJson(doc, json);
|
||||
CHECK(err == DeserializationError::Ok);
|
||||
@ -279,7 +290,7 @@ TEST_CASE("copyArray()") {
|
||||
}
|
||||
|
||||
SECTION("JsonArray -> int[][]") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[] = "[[1,2],[3],[4]]";
|
||||
|
||||
DeserializationError err = deserializeJson(doc, json);
|
||||
@ -298,7 +309,7 @@ TEST_CASE("copyArray()") {
|
||||
}
|
||||
|
||||
SECTION("JsonDocument -> int[][]") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[] = "[[1,2],[3],[4]]";
|
||||
|
||||
DeserializationError err = deserializeJson(doc, json);
|
||||
@ -316,7 +327,7 @@ TEST_CASE("copyArray()") {
|
||||
}
|
||||
|
||||
SECTION("MemberProxy -> int[][]") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
char json[] = "{\"data\":[[1,2],[3],[4]]}";
|
||||
|
||||
DeserializationError err = deserializeJson(doc, json);
|
||||
|
21
extras/tests/JsonArray/createNested.cpp
Normal file
21
extras/tests/JsonArray/createNested.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("JsonArray basics") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArray array = doc.to<JsonArray>();
|
||||
|
||||
SECTION("CreateNestedArray") {
|
||||
JsonArray arr = array.createNestedArray();
|
||||
REQUIRE(arr == array[0].as<JsonArray>());
|
||||
}
|
||||
|
||||
SECTION("CreateNestedObject") {
|
||||
JsonObject obj = array.createNestedObject();
|
||||
REQUIRE(obj == array[0].as<JsonObject>());
|
||||
}
|
||||
}
|
@ -1,22 +1,25 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <catch.hpp>
|
||||
|
||||
TEST_CASE("JsonArray::operator==()") {
|
||||
JsonDocument doc1;
|
||||
DynamicJsonDocument doc1(4096);
|
||||
JsonArray array1 = doc1.to<JsonArray>();
|
||||
JsonArrayConst array1c = array1;
|
||||
|
||||
JsonDocument doc2;
|
||||
DynamicJsonDocument doc2(4096);
|
||||
JsonArray array2 = doc2.to<JsonArray>();
|
||||
JsonArrayConst array2c = array2;
|
||||
|
||||
SECTION("should return false when arrays differ") {
|
||||
array1.add("coucou");
|
||||
array2.add(1);
|
||||
|
||||
REQUIRE_FALSE(array1 == array2);
|
||||
REQUIRE_FALSE(array1c == array2c);
|
||||
}
|
||||
|
||||
SECTION("should return false when LHS has more elements") {
|
||||
@ -25,6 +28,7 @@ TEST_CASE("JsonArray::operator==()") {
|
||||
array2.add(1);
|
||||
|
||||
REQUIRE_FALSE(array1 == array2);
|
||||
REQUIRE_FALSE(array1c == array2c);
|
||||
}
|
||||
|
||||
SECTION("should return false when RHS has more elements") {
|
||||
@ -33,6 +37,7 @@ TEST_CASE("JsonArray::operator==()") {
|
||||
array2.add(2);
|
||||
|
||||
REQUIRE_FALSE(array1 == array2);
|
||||
REQUIRE_FALSE(array1c == array2c);
|
||||
}
|
||||
|
||||
SECTION("should return true when arrays equal") {
|
||||
@ -40,6 +45,7 @@ TEST_CASE("JsonArray::operator==()") {
|
||||
array2.add("coucou");
|
||||
|
||||
REQUIRE(array1 == array2);
|
||||
REQUIRE(array1c == array2c);
|
||||
}
|
||||
|
||||
SECTION("should return false when RHS is null") {
|
||||
|
@ -1,5 +1,5 @@
|
||||
// ArduinoJson - https://arduinojson.org
|
||||
// Copyright © 2014-2024, Benoit BLANCHON
|
||||
// Copyright © 2014-2023, Benoit BLANCHON
|
||||
// MIT License
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
@ -12,12 +12,25 @@ TEST_CASE("JsonArray::isNull()") {
|
||||
}
|
||||
|
||||
SECTION("returns false") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArray arr = doc.to<JsonArray>();
|
||||
REQUIRE(arr.isNull() == false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonArrayConst::isNull()") {
|
||||
SECTION("returns true") {
|
||||
JsonArrayConst arr;
|
||||
REQUIRE(arr.isNull() == true);
|
||||
}
|
||||
|
||||
SECTION("returns false") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArrayConst arr = doc.to<JsonArray>();
|
||||
REQUIRE(arr.isNull() == false);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonArray::operator bool()") {
|
||||
SECTION("returns false") {
|
||||
JsonArray arr;
|
||||
@ -25,8 +38,21 @@ TEST_CASE("JsonArray::operator bool()") {
|
||||
}
|
||||
|
||||
SECTION("returns true") {
|
||||
JsonDocument doc;
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArray arr = doc.to<JsonArray>();
|
||||
REQUIRE(static_cast<bool>(arr) == true);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("JsonArrayConst::operator bool()") {
|
||||
SECTION("returns false") {
|
||||
JsonArrayConst arr;
|
||||
REQUIRE(static_cast<bool>(arr) == false);
|
||||
}
|
||||
|
||||
SECTION("returns true") {
|
||||
DynamicJsonDocument doc(4096);
|
||||
JsonArrayConst arr = doc.to<JsonArray>();
|
||||
REQUIRE(static_cast<bool>(arr) == true);
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user