public <T> String export(DataBoundConfigurator<T> configurator, T object) throws Exception {
        ConfigurationAsCode casc = ConfigurationAsCode.get();
        ConfiguratorRegistry registry = ConfiguratorRegistry.get();
        ConfigurationContext context = new ConfigurationContext(registry);

        final CNode config = configurator.describe(object, context);
        final Node valueNode = casc.toYaml(config);

        try (StringWriter writer = new StringWriter()) {
            ConfigurationAsCode.serializeYamlNode(valueNode, writer);
            return writer.toString();
        } catch (IOException e) {
            throw new YAMLException(e);
        }
    }
Contains tests for particular export cases.
plugin/src/test/java/io/jenkins/plugins/casc/yaml/ExportTest.java