package liquibase.parser.core.yaml;

import liquibase.database.Database;
import liquibase.database.DatabaseFactory;
import liquibase.exception.LiquibaseParseException;
import liquibase.parser.SnapshotParser;
import liquibase.parser.core.ParsedNode;
import liquibase.resource.ResourceAccessor;
import liquibase.snapshot.DatabaseSnapshot;
import liquibase.snapshot.EmptyDatabaseSnapshot;
import liquibase.snapshot.RestoredDatabaseSnapshot;
import liquibase.util.StreamUtil;
import org.yaml.snakeyaml.Yaml;

import java.io.InputStream;
import java.util.List;
import java.util.Map;

public class YamlSnapshotParser extends YamlParser implements SnapshotParser {

    @Override
    public DatabaseSnapshot parse(String path, ResourceAccessor resourceAccessor) throws LiquibaseParseException {
        Yaml yaml = new Yaml();

        try {
            InputStream stream = StreamUtil.singleInputStream(path, resourceAccessor);
            if (stream == null) {
                throw new LiquibaseParseException(path + " does not exist");
            }

            Map parsedYaml;
            try {
                parsedYaml = yaml.loadAs(stream, Map.class);
            } catch (Exception e) {
                throw new LiquibaseParseException("Syntax error in " + getSupportedFileExtensions()[0] + ": " + e.getMessage(), e);
            }

            Map rootList = (Map) parsedYaml.get("snapshot");
            if (rootList == null) {
                throw new LiquibaseParseException("Could not find root snapshot node");
            }

            String shortName = (String) ((Map) rootList.get("database")).get("shortName");

            Database database = DatabaseFactory.getInstance().getDatabase(shortName).getClass().newInstance();
            DatabaseSnapshot snapshot = new RestoredDatabaseSnapshot(database);
            ParsedNode snapshotNode = new ParsedNode(null, "snapshot");
            snapshotNode.setValue(rootList);

            snapshot.load(snapshotNode, resourceAccessor);

            return snapshot;
        } catch (Throwable e) {
            if (e instanceof LiquibaseParseException) {
                throw (LiquibaseParseException) e;
            }
            throw new LiquibaseParseException(e);
        }
    }
}

@@ -526,16 +526,50 @@
 Stream;%0A
+import java.io.InputStreamReader;%0A
 import j
@@ -1162,22 +1162,54 @@
 .loadAs(
-stream
+new InputStreamReader(stream, %22UTF-8%22)
 , Map.cl

Load yaml as utf-8