Skip to content

Commit 59066bd

Browse files
atanisoftme-no-dev
authored andcommitted
PrettyAsyncJsonResponse for ArduinoJson 6.x (me-no-dev#539)
* PrettyAsyncJsonResponse for ArduinoJson 6.x add support for PrettyAsyncJsonResponse in ArduinoJson 6.x * Update AsyncJson.h Maintain order of args to AsyncJsonResponse between ArduinoJson 5.x and 6.x compatibility for ease of migration
1 parent 69aaf76 commit 59066bd

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/AsyncJson.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class AsyncJsonResponse: public AsyncAbstractResponse {
101101
_root = _jsonBuffer.createObject();
102102
}
103103
#else
104-
AsyncJsonResponse(size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE, bool isArray=false) : _jsonBuffer(maxJsonBufferSize), _isValid{false} {
104+
AsyncJsonResponse(bool isArray=false, size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE) : _jsonBuffer(maxJsonBufferSize), _isValid{false} {
105105
_code = 200;
106106
_contentType = JSON_MIMETYPE;
107107
if(isArray)
@@ -140,18 +140,25 @@ class AsyncJsonResponse: public AsyncAbstractResponse {
140140
}
141141
};
142142

143-
#ifdef ARDUINOJSON_5_COMPATIBILITY
144143
class PrettyAsyncJsonResponse: public AsyncJsonResponse {
145144
public:
146145
PrettyAsyncJsonResponse (bool isArray=false) : AsyncJsonResponse{isArray} {}
147146
size_t setLength () {
147+
#ifdef ARDUINOJSON_5_COMPATIBILITY
148148
_contentLength = _root.measurePrettyLength ();
149+
#else
150+
_contentLength = measureJsonPretty(_root);
151+
#endif
149152
if (_contentLength) {_isValid = true;}
150153
return _contentLength;
151154
}
152155
size_t _fillBuffer (uint8_t *data, size_t len) {
153156
ChunkPrint dest (data, _sentLength, len);
157+
#ifdef ARDUINOJSON_5_COMPATIBILITY
154158
_root.prettyPrintTo (dest);
159+
#else
160+
serializeJsonPretty(_root, dest);
161+
#endif
155162
return len;
156163
}
157164
};

0 commit comments

Comments
 (0)