Problems with XStream 1.4 migration

Hello everyone,

we are running into problems while upgrading our Confluence plugin for Confluence 9. We want to migrate our existing Bandana persistence layer to use the proper APIs for persistence in the newer Confluence versions. For this, we were trying to follow this article: XStream 1.4 upgrade | Confluence Data Center 9.3 | Atlassian Documentation

There are more than just one Bandana contexts with multiple aliases which I left out for clarity.

Previous versions of our plugin have used custom XStream logic by implementing the BandanaSerializerFactory interface for the context. This looked like this:

    @Override
    public BandanaSerializer getSerializer() {
        XStream xStream = new XStream();
        xStream.setClassLoader(getClass().getClassLoader());
        xStream.alias("sync", SmartLinkSyncTask.class);
        xStream.allowTypes(new Class[]{SmartLinkSyncTask.class});
        return new XStreamBandanaSerializer(xStream);
    }

As far as we understand, XStreamManagerCompat is supposed to bridge this gap and provide the necessary functionality without plugins directly using XStream. We therefore removed the implementation for BandanaSerializerFactory, which helped us make the plugin run at all (as we were no longer relying on XStream directly).

Most important for us in this migration is the alias, we want to keep all the existing data available to the users of our plugin. However, everything that we have tried has either not correctly registered the alias or broken the plugin in some other way. Our current approach is attempting to register the alias in a separate class:

@Named
public class XStreamAliasProvider {
    public XStreamAliasProvider() {
        XStreamManagerCompat manager = new XStreamManagerCompat();

        manager.alias("sync", SmartLinkSyncTask.class);
    }
}

Where should we put the alias definitions so that they are correctly picked up by the persistence API?

Thanks for your help!

Solved it, this is what our implementation of BandanaSerializerFactory looks like now:

    @Override
    public BandanaSerializer getSerializer() {
        XStreamManagerCompat manager = new XStreamManagerCompat();
        manager.alias("sync", SmartLinkSyncTask.class);

        return new BandanaSerializer() {
            @Override
            public void serialize(Object obj, Writer writer) {
                manager.toXML(obj, writer);
            }

            @Override
            public Object deserialize(Reader reader) {
                return manager.fromXML(reader);
            }
        };
    }