Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stringstream not working on esp32 #1156

Closed
LeonB opened this issue Dec 28, 2019 · 1 comment
Closed

stringstream not working on esp32 #1156

LeonB opened this issue Dec 28, 2019 · 1 comment
Labels
v6 ArduinoJson 6

Comments

@LeonB
Copy link

LeonB commented Dec 28, 2019

I'm using ArduinoJson on an esp32.

This works:

    DynamicJsonDocument doc(1024);
    doc["reading"] = "test";

    String s;
    serializeJson(doc, s);
    Serial.println(s);

This works:

    DynamicJsonDocument doc(1024);
    doc["reading"] = "test";

    std::string s;
    serializeJson(doc, s);
    Serial.println(s.c_str());

But as soon as I try to use std::stringstream I get a compile error:

    DynamicJsonDocument doc(1024);
    doc["reading"] = "test";

    std::stringstream ss();
    serializeJson(doc, ss);
libraries/ArduinoJson/src/ArduinoJson/Json/TextFormatter.hpp:129:13:   required from 'void ArduinoJson6130_000001::TextFormatter<TWriter>::writeRaw(const char*) [with TWriter = ArduinoJson6130_000001::Writer<std::__cxx11::basic_stringstream<char>(), void>]'
libraries/ArduinoJson/src/ArduinoJson/Json/JsonSerializer.hpp:80:5:   required from 'void ArduinoJson6130_000001::JsonSerializer<TWriter>::visitNull() [with TWriter = ArduinoJson6130_000001::Writer<std::__cxx11::basic_stringstream<char>(), void>]'
libraries/ArduinoJson/src/ArduinoJson/Variant/VariantFunctions.hpp:16:5:   required from 'void ArduinoJson6130_000001::variantAccept(const ArduinoJson6130_000001::VariantData*, Visitor&) [with Visitor = ArduinoJson6130_000001::JsonSerializer<ArduinoJson6130_000001::Writer<std::__cxx11::basic_stringstream<char>(), void> >]'
libraries/ArduinoJson/src/ArduinoJson/Variant/VariantRef.hpp:352:18:   required from 'void ArduinoJson6130_000001::VariantConstRef::accept(Visitor&) const [with Visitor = ArduinoJson6130_000001::JsonSerializer<ArduinoJson6130_000001::Writer<std::__cxx11::basic_stringstream<char>(), void> >]'
libraries/ArduinoJson/src/ArduinoJson/Document/JsonDocument.hpp:20:39:   required from 'void ArduinoJson6130_000001::JsonDocument::accept(Visitor&) const [with Visitor = ArduinoJson6130_000001::JsonSerializer<ArduinoJson6130_000001::Writer<std::__cxx11::basic_stringstream<char>(), void> >]'
libraries/ArduinoJson/src/ArduinoJson/Serialization/serialize.hpp:15:3:   required from 'size_t ArduinoJson6130_000001::doSerialize(const TSource&, TWriter) [with TSerializer = ArduinoJson6130_000001::JsonSerializer; TSource = ArduinoJson6130_000001::BasicJsonDocument<ArduinoJson6130_000001::DefaultAllocator>; TWriter = ArduinoJson6130_000001::Writer<std::__cxx11::basic_stringstream<char>(), void>; size_t = unsigned int]'
libraries/ArduinoJson/src/ArduinoJson/Serialization/serialize.hpp:23:34:   required from 'size_t ArduinoJson6130_000001::serialize(const TSource&, TDestination&) [with TSerializer = ArduinoJson6130_000001::JsonSerializer; TSource = ArduinoJson6130_000001::BasicJsonDocument<ArduinoJson6130_000001::DefaultAllocator>; TDestination = std::__cxx11::basic_stringstream<char>(); size_t = unsigned int]'
libraries/ArduinoJson/src/ArduinoJson/Json/JsonSerializer.hpp:102:35:   required from 'size_t ArduinoJson6130_000001::serializeJson(const TSource&, TDestination&) [with TSource = ArduinoJson6130_000001::BasicJsonDocument<ArduinoJson6130_000001::DefaultAllocator>; TDestination = std::__cxx11::basic_stringstream<char>(); size_t = unsigned int]'
src/Server.ino:92:26:   required from here
libraries/ArduinoJson/src/ArduinoJson/Serialization/Writer.hpp:22:29: error: request for member 'write' in '*((ArduinoJson6130_000001::Writer<std::__cxx11::basic_stringstream<char>(), void>*)this)->ArduinoJson6130_000001::Writer<std::__cxx11::basic_stringstream<char>(), void>::_dest', which is of non-class type 'std::__cxx11::basic_stringstream<char>()'
     return _dest->write(s, n);
                             ^
libraries/ArduinoJson/src/ArduinoJson/Serialization/Writer.hpp: In instantiation of 'size_t ArduinoJson6130_000001::Writer<TDestination, Enable>::write(uint8_t) [with TDestination = std::__cxx11::basic_stringstream<char>(); Enable = void; size_t = unsigned int; uint8_t = unsigned char]':
libraries/ArduinoJson/src/ArduinoJson/Json/TextFormatter.hpp:146:13:   required from 'void ArduinoJson6130_000001::TextFormatter<TWriter>::writeRaw(char) [with TWriter = ArduinoJson6130_000001::Writer<std::__cxx11::basic_stringstream<char>(), void>]'
libraries/ArduinoJson/src/ArduinoJson/Json/TextFormatter.hpp:69:15:   required from 'void ArduinoJson6130_000001::TextFormatter<TWriter>::writeFloat(T) [with T = float; TWriter = ArduinoJson6130_000001::Writer<std::__cxx11::basic_stringstream<char>(), void>]'
libraries/ArduinoJson/src/ArduinoJson/Json/JsonSerializer.hpp:56:5:   required from 'void ArduinoJson6130_000001::JsonSerializer<TWriter>::visitFloat(ArduinoJson6130_000001::Float) [with TWriter = ArduinoJson6130_000001::Writer<std::__cxx11::basic_stringstream<char>(), void>; ArduinoJson6130_000001::Float = float]'
libraries/ArduinoJson/src/ArduinoJson/Variant/VariantData.hpp:30:51:   required from 'void ArduinoJson6130_000001::VariantData::accept(Visitor&) const [with Visitor = ArduinoJson6130_000001::JsonSerializer<ArduinoJson6130_000001::Writer<std::__cxx11::basic_stringstream<char>(), void> >]'
libraries/ArduinoJson/src/ArduinoJson/Variant/VariantFunctions.hpp:14:5:   required from 'void ArduinoJson6130_000001::variantAccept(const ArduinoJson6130_000001::VariantData*, Visitor&) [with Visitor = ArduinoJson6130_000001::JsonSerializer<ArduinoJson6130_000001::Writer<std::__cxx11::basic_stringstream<char>(), void> >]'
libraries/ArduinoJson/src/ArduinoJson/Variant/VariantRef.hpp:352:18:   required from 'void ArduinoJson6130_000001::VariantConstRef::accept(Visitor&) const [with Visitor = ArduinoJson6130_000001::JsonSerializer<ArduinoJson6130_000001::Writer<std::__cxx11::basic_stringstream<char>(), void> >]'
libraries/ArduinoJson/src/ArduinoJson/Document/JsonDocument.hpp:20:39:   required from 'void ArduinoJson6130_000001::JsonDocument::accept(Visitor&) const [with Visitor = ArduinoJson6130_000001::JsonSerializer<ArduinoJson6130_000001::Writer<std::__cxx11::basic_stringstream<char>(), void> >]'
libraries/ArduinoJson/src/ArduinoJson/Serialization/serialize.hpp:15:3:   required from 'size_t ArduinoJson6130_000001::doSerialize(const TSource&, TWriter) [with TSerializer = ArduinoJson6130_000001::JsonSerializer; TSource = ArduinoJson6130_000001::BasicJsonDocument<ArduinoJson6130_000001::DefaultAllocator>; TWriter = ArduinoJson6130_000001::Writer<std::__cxx11::basic_stringstream<char>(), void>; size_t = unsigned int]'
libraries/ArduinoJson/src/ArduinoJson/Serialization/serialize.hpp:23:34:   required from 'size_t ArduinoJson6130_000001::serialize(const TSource&, TDestination&) [with TSerializer = ArduinoJson6130_000001::JsonSerializer; TSource = ArduinoJson6130_000001::BasicJsonDocument<ArduinoJson6130_000001::DefaultAllocator>; TDestination = std::__cxx11::basic_stringstream<char>(); size_t = unsigned int]'
libraries/ArduinoJson/src/ArduinoJson/Json/JsonSerializer.hpp:102:35:   required from 'size_t ArduinoJson6130_000001::serializeJson(const TSource&, TDestination&) [with TSource = ArduinoJson6130_000001::BasicJsonDocument<ArduinoJson6130_000001::DefaultAllocator>; TDestination = std::__cxx11::basic_stringstream<char>(); size_t = unsigned int]'
src/Server.ino:92:26:   required from here
libraries/ArduinoJson/src/ArduinoJson/Serialization/Writer.hpp:18:26: error: request for member 'write' in '*((ArduinoJson6130_000001::Writer<std::__cxx11::basic_stringstream<char>(), void>*)this)->ArduinoJson6130_000001::Writer<std::__cxx11::basic_stringstream<char>(), void>::_dest', which is of non-class type 'std::__cxx11::basic_stringstream<char>()'
     return _dest->write(c);
                          ^

I've defined ARDUINOJSON_ENABLE_STD_STREAM:

#define ARDUINOJSON_ENABLE_STD_STREAM 1

In the tests I see std::stringstream is used. What is going wrong here? I'm using the makeEspArduino makefile.

@LeonB LeonB changed the title stringstream not working stringstream not working on esp32 Dec 28, 2019
@bblanchon
Copy link
Owner

Hi @LeonB,

Are you sure you defined ARDUINOJSON_ENABLE_STD_STREAM before including ArduinoJson.h?
If you have multiple compilation units, make sure you use the same settings, the best is to set the defines in the Makefile.

Meanwhile, I'll add some code to auto-enable support std::stream base on the new __has_header directive introduced in C++17.

Best regards,
Benoit.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 3, 2020
stawiski pushed a commit to stawiski/ArduinoJson that referenced this issue Jul 28, 2020
@bblanchon bblanchon added the v6 ArduinoJson 6 label Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
v6 ArduinoJson 6
Projects
None yet
Development

No branches or pull requests

2 participants