diff --git a/src/AsyncJson.h b/src/AsyncJson.h index 4a6d6ba..6118afe 100644 --- a/src/AsyncJson.h +++ b/src/AsyncJson.h @@ -101,7 +101,7 @@ class AsyncJsonResponse: public AsyncAbstractResponse { _root = _jsonBuffer.createObject(); } #else - AsyncJsonResponse(size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE, bool isArray=false) : _jsonBuffer(maxJsonBufferSize), _isValid{false} { + AsyncJsonResponse(bool isArray=false, size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE) : _jsonBuffer(maxJsonBufferSize), _isValid{false} { _code = 200; _contentType = JSON_MIMETYPE; if(isArray) @@ -140,18 +140,25 @@ class AsyncJsonResponse: public AsyncAbstractResponse { } }; -#ifdef ARDUINOJSON_5_COMPATIBILITY class PrettyAsyncJsonResponse: public AsyncJsonResponse { public: PrettyAsyncJsonResponse (bool isArray=false) : AsyncJsonResponse{isArray} {} size_t setLength () { +#ifdef ARDUINOJSON_5_COMPATIBILITY _contentLength = _root.measurePrettyLength (); +#else + _contentLength = measureJsonPretty(_root); +#endif if (_contentLength) {_isValid = true;} return _contentLength; } size_t _fillBuffer (uint8_t *data, size_t len) { ChunkPrint dest (data, _sentLength, len); +#ifdef ARDUINOJSON_5_COMPATIBILITY _root.prettyPrintTo (dest); +#else + serializeJsonPretty(_root, dest); +#endif return len; } };