java properties to json

后端 未结 10 1598
情书的邮戳
情书的邮戳 2020-12-13 18:06

Is there an easy way to convert properties with dot notation to json

I.E

server.host=foo.bar
server.port=1234

TO

{
         


        
10条回答
  •  悲哀的现实
    2020-12-13 18:37

    Using lightbend config java library (https://github.com/lightbend/config)

    String toHierarchicalJsonString(Properties props) {
      com.typesafe.config.Config config = com.typesafe.config.ConfigFactory.parseProperties(props);
      return config.root().render(com.typesafe.config.ConfigRenderOptions.concise());
    }
    

提交回复
热议问题