java - SnakeYAML saves incorrectly -
i've been working on setting configuration use snakeyaml. want configuration this:
connection: bind-ip: 0.0.0.0 plugin-port: 2011 rtk-port: 2012 passphrase: abcde12345 updates: auto-update: true channel: recommended build: -1
but instead turns out
connection: {bind-ip: 0.0.0.0, connection.passphrase: abcde12345, connection.pluginport: 2011, connection.rtkport: 2012} updates: {updates.auto-update: true, updates.channel: recommended, updates.build: -1}
i have linkedhashmap save so:
private linkedhashmap<string, map> values; public void set(string key, map<string, object> value) { values.put(key, value); }
and here method use populate/load configuration
private void init() { map<string, object> connection = new linkedhashmap<string, object>(); if (exists("connection.bind-ip")) { bindip = (string) get("connection.bind-ip"); } else { connection.put("bind-ip", bindip); } if (exists("connection.passphrase")) { passphrase = (string) get("connection.passphrase"); } else { connection.put("connection.passphrase", passphrase); } if (exists("connection.pluginport")) { pluginport = (integer) get("connection.rtkport"); } else { connection.put("connection.pluginport", pluginport); } if (exists("connection.rtkport")) { rtkport = (integer) get("connection.rtkport"); } else { connection.put("connection.rtkport", rtkport); } if (!(connection.isempty())) { set("connection", connection); } map<string, object> updates = new linkedhashmap<string, object>(); if (exists("updates.auto-update")) { autoupdate = (boolean) get("updates.auto-update"); } else { updates.put("updates.auto-update", autoupdate); } if (exists("updates.channel")) { channel = (string) get("updates.channel"); } else { updates.put("updates.channel", channel); } if (exists("updates.build")) { build = (integer) get("updates.build"); } else { updates.put("updates.build", build); } if (!(updates.isempty())) { set("updates", updates); } }
any appreciated! sorry it's little long
simple answer. when create yaml, use dumperoptions
, set dumperoptions.setdefaultflowstyle(dumperoptions.flowstyle.block)
, , set. can't believe missed :(
Comments
Post a Comment