ValueTree::writeToStream with Array<var> fails


The following code jasserts at the end, am I doing something wrong?

void SineSynthAudioProcessor::getStateInformation (MemoryBlock& destData)
	ValueTree vt("state");
	Array<var> temp;
	for (int i = 0; i < m_data.size(); ++i)
	vt.setProperty("data0", temp, nullptr);
	MemoryOutputStream ms(destData,false);
	ValueTree foo = ValueTree::readFromData(destData.getData(), destData.getSize());
		Array<var> bar = foo.getProperty("data0").getArray();
		jassert(bar.size() == m_data.size());

Or doesn’t ValueTree::writeToStream support properties that are arrays? Shouldn’t there be an internal JUCE jassert in that case like there is when attempting to serialize the tree to xml?


XML doesn’t have syntax support for arrays.
I think you’ll hit this assertion if you write it to XML:

void NamedValueSet::copyToXmlAttributes (XmlElement& xml) const
    for (auto& i : values)
        if (auto* mb = i.value.getBinaryData())
            xml.setAttribute ("base64:" +, mb->toBase64Encoding());
            // These types can't be stored as XML!
            jassert (! i.value.isObject());
            jassert (! i.value.isMethod());
            jassert (! i.value.isArray());

            xml.setAttribute (,

Oddly, it looks like it should actually work with the binary format though…

I’d put some breakpoints in var::readFromStream/var::writeToStream to see what’s going on.


Yes, that’s what I meant, because the xml writing jasserts because it doesn’t support it, I would expect the binary writing to do the same the thing if it doesn’t support the arrays and objects.