Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing array elements in a TypeSafe configuration

Given a nested JSON as configuration, like:

{
    app: {
        id: "app1"
        instances: 2,
        servers: [
            { host: "farm1.myco.com", port: 9876 }
            { host: "farm2.myco.com", port: 9876 }
        ]
    }
}

When using typeSafe config, is it possible to address elements of an array directly in a path?

At the moment we need to do something like the following, which is kind of verbose:

val servers = config.getObjectList("app.servers")
val server = servers.get(0).toConfig
val host = server.getString("host")
val port = server.getInt("port")

Something like this would be ideal:

val host = config.getString("app.servers.0.host") ?

Does the TypeSafe API supports something like this?

like image 425
maasg Avatar asked Sep 23 '14 12:09

maasg


1 Answers

This seems not possible so far.
See https://github.com/typesafehub/config/issues/30

like image 119
George Avatar answered Nov 09 '22 10:11

George