import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.toml.TomlMapper; public class TomlExample { public static void main(String[] args) { String tomlData = "[server] host = \"localhost\" port = 8080"; ObjectMapper mapper = new TomlMapper(); try { ServerConfig config = mapper.readValue(tomlData, ServerConfig.class); System.out.println("Host: " + config.getServer().getHost()); System.out.println("Port: " + config.getServer().getPort()); } catch (Exception e) { e.printStackTrace(); } } static class ServerConfig { private Server server; public Server getServer() { return server; } public void setServer(Server server) { this.server = server; } } static class Server { private String host; private int port; public String getHost() { return host; } public void setHost(String host) { this.host = host; } public int getPort() { return port; } public void setPort(int port) { this.port = port; } } }


上一篇:
下一篇:
切换中文