Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5977759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:25:00+00:00 2026-05-22T21:25:00+00:00

I’m using boost::serialize to serialize a document wherein I use f.i. a juce::String. Like

  • 0

I’m using boost::serialize to serialize a document wherein I use f.i. a juce::String. Like so:

template<class Archive>
void serialize( Archive & ar, const unsigned int version )
{
    ar & boost::serialization::make_nvp("title", m_docTitle);
    ...
}

For boost::serialize to accept juce::String as a primitive type I did:

#include <boost/serialization/string.hpp>

template<class IStream>
inline IStream& operator >> (IStream& stream, juce::String& s)
{
    std::wstring t;
    stream >> t;
    s = juce::String(t.c_str());
    return stream;
}

BOOST_CLASS_IMPLEMENTATION(juce::String, boost::serialization::primitive_type)

which compiles nicely. Serialization works fine, I get the entry in the XML:

<title>DocumentTitle</title>

as it should be. However when deserializing I can trace in the >> operator that the string returned is:

"DocumentTitle</title>"

i.e. some of the XML has been “chewed up”, which later of course leads to an “input stream error” exception.

The oddest part is though that I had this working up until a week ago… 🙁 and I have no idea what makes it NOT work now…

Edit: A little example code that shows reproduces the behavior, only dependency is boost:

#include <boost/serialization/serialization.hpp>
#include <boost/serialization/string.hpp>

#include <boost/archive/xml_woarchive.hpp>
#include <boost/archive/xml_wiarchive.hpp>
#include <sstream>

class JuceString
{
public:
    JuceString(const std::wstring& str = L"") : m_str(str) {;}
    JuceString(const JuceString& other) : m_str(other.m_str) {;}
    JuceString& operator = (const JuceString& other)
    {
        if (this != &other)
        {
            m_str = other.m_str;
        }
        return *this;
    }
    const wchar_t* toWideCharPointer() const {
        return m_str.c_str();
    }

private:
    std::wstring m_str;
};

template <class OStream>
OStream& operator<< (OStream& stream, const JuceString& stringToWrite)
{
    return stream << stringToWrite.toWideCharPointer();
}

template <class IStream>
IStream& operator>> (IStream& stream, JuceString& s)
{
    std::wstring t;
    stream >> t;
    s = JuceString(t.c_str());
    return stream;
}

BOOST_CLASS_IMPLEMENTATION(JuceString, boost::serialization::primitive_type)


class Doc
{
    friend class boost::serialization::access;

    template<class Archive>
    void serialize( Archive & ar, const unsigned int version )
    {
        ar & boost::serialization::make_nvp("title", m_title);
    }

public:
    Doc() {;}
    Doc(const std::wstring& s) : m_title(s) {;}

private:
    JuceString m_title;
};


int main (int argc, char* argv[])
{
    std::wstringstream stream;
    {
        // Serializing document
        Doc doc(L"DocumentTitle");
        boost::archive::xml_woarchive oa(stream);
        oa << boost::serialization::make_nvp("Document", doc);
    }
    {
        // Deserializing document
        Doc doc;
        try
        {
            boost::archive::xml_wiarchive ia(stream);
            ia >> boost::serialization::make_nvp("Document", doc);
        }
        catch (std::exception& e)
        {
            std::cerr << e.what() << std::endl;
        }

    }
    return 0;
}

Using the text archive instead works just fine both ways…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:25:01+00:00Added an answer on May 22, 2026 at 9:25 pm

    Finally I got it to work (for XML archive nota bene), by using boost basic_xml_grammar to parse the string in operator>> , like so:

    typedef boost::archive::basic_xml_grammar<wchar_t> xml_wgrammar;
    
    template <class IStream>
    IStream& operator>> (IStream& stream, JuceString& s)
    {
        std::wstring t;
        xml_wgrammar grammar;
        if (!grammar.parse_string(stream, t))
        {
            boost::serialization::throw_exception(
                boost::archive::xml_archive_exception(boost::archive::xml_archive_exception::xml_archive_parsing_error)
            );
        }
        s = JuceString(t.c_str());
        return stream;
    }
    

    That will make sure that the string is parsed correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.