Skip to content

using dump() when std::wstring is StringType with VS2017 #836

Description

@TobiSchluter

I may be doing something stupid, but I'm trying to use std::wstring as my string type. If I call json::dump on my wstring'ed json object, it seems to not be able to convert from char to wchar_t if I correctly understand an error message that is too verbose to not be opaque. I quote the errors at the bottom. This is with VisualStudio 2017. I cloned the git repo a few weeks ago, and haven't tried with the latest version, but I didn't see any pertinent checkins in the meantime. I may have missed them of course. Likewise for examples that use a different string type, I also didn't find any closed issues referring to wchar_t or std::wstring.

My declarations look like:

        namespace utility { typedef string_t std::wstring; }
        nlohmann::basic_json<std::map, std::vector, utility::string_t> j = njson::parse(wbody); // here wbody is of type std::wstring

and the call to dump is
utility::string_t dump = j.dump(0); // again utility::string_t is std::wstring.

Is this expected?

Thank you for your good work. The library has really made my life a lot easier.

(The first warning always appears when including the header, and is unrelated.)

1>C:\tobi\Source\json/json.hpp(5961): warning C4819: The file contains a character that cannot be represented in the current code page (932). Save the file in Unicode format to prevent data loss
1>C:\tobi\Source\json/json.hpp(8999): error C2440: '<function-style-cast>': cannot convert from 'std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>' to 'nlohmann::detail::output_adapter<char>'
1>C:\tobi\Source\json/json.hpp(8999): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>C:\tobi\Source\json/json.hpp(8997): note: while compiling class template member function 'std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>> nlohmann::basic_json<std::map,std::vector,utility::string_t,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::dump(const int,const char,const bool) const'
1>C:\tobi\Source\source.cpp(57): note: see reference to function template instantiation 'std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>> nlohmann::basic_json<std::map,std::vector,utility::string_t,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>::dump(const int,const char,const bool) const' being compiled
1>C:\tobi\Source\source.cpp(34): note: see reference to class template instantiation 'nlohmann::basic_json<std::map,std::vector,utility::string_t,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>' being compiled
1>C:\tobi\Source\json/json.hpp(8999): error C2664: 'nlohmann::detail::serializer<nlohmann::basic_json<std::map,std::vector,utility::string_t,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>::serializer(const nlohmann::detail::serializer<nlohmann::basic_json<std::map,std::vector,utility::string_t,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>> &)': cannot convert argument 1 from 'const char' to 'const nlohmann::detail::serializer<nlohmann::basic_json<std::map,std::vector,utility::string_t,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>> &'
1>C:\tobi\Source\json/json.hpp(8999): note: Reason: cannot convert from 'const char' to 'const nlohmann::detail::serializer<nlohmann::basic_json<std::map,std::vector,utility::string_t,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>>'
1>C:\tobi\Source\json/json.hpp(8999): note: No constructor could take the source type, or constructor overload resolution was ambiguous

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    solution: wontfixthe issue will not be fixed (either it is impossible or deemed out of scope)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions