HOCON Substitution default value

最后都变了- 提交于 2019-12-08 16:53:53

问题


In HOCON and Typesafe Config, How do I set the default value in case of substitution.

Does it supports something like this ??

${server.host: 'localhost'} -> If server.host set(Either in the same configu files or through environement setting) it substitutes that if not set choose the default value


回答1:


From the official docs on substitutions:

If a substitution with the ${?foo} syntax is undefined:

  • if it is the value of an object field then the field should not be created. If the field would have overridden a previously-set value for the same field, then the previous value remains.

So here is one possible workaround using object merging:

defaults {
  foo: "default Value"
}

item = ${defaults} {
  foo: ${?bar}
}

Or even simplier:

item = {
  foo: "default Value"
  foo: ${?bar}
}


来源:https://stackoverflow.com/questions/38822992/hocon-substitution-default-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!