简体   繁体   中英

How to parse typesafe config with objects

I have a config application.conf :

usersHasPermissions = [
  {"login": "admin", "perms": ["p1", "p2"]},
  {"login": "petooh", "perms": ["p2"]},
  {"login": "*", "perms": ["p3"]}
]

How I can parse it to Map[String,Set[String] , where "login" - key, "perms" - set?

I can render it as json and parse. But I didn't want include json library in project. I think there is solution with ConfigObject etc.

Ok, it's simple:

config.getObjectList("usersHasPermissions").asScala.map(o =>
      o.toConfig.getString("login") ->
        o.toConfig.getStringList("perms").asScala.toSet).toMap

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM