Do we have a proper serializable for HOCON which would respect the order or does a inline replacement in java?

huangapple 未分类评论45阅读模式
英文:

Do we have a proper serializable for HOCON which would respect the order or does a inline replacement in java?

问题

我正在开发一个Java应用程序,其中包含一个配置文件(我选择使用HOCON,如果有其他选项,请告诉我满足我要求的选项),以及一个用于编辑配置文件的用户界面。

用户可以直接编辑配置文件,也可以使用用户界面。配置文件可以包含注释。

如果用户使用界面编辑文件,当他们点击保存时,我需要更新配置文件。

我正在使用lightbend/config来读取和写入配置文件。

ConfigRenderOptions renderOpts = ConfigRenderOptions.defaults().setOriginComments(false).setJson(false);
String writeString = tsConfig.root().render(renderOpts);

但是写入的问题是,它不保持参数的顺序,注释也会混乱。请参见下面的图片:

Do we have a proper serializable for HOCON which would respect the order or does a inline replacement in java?

我的要求是要有一个写入器,可以保持注释和参数的顺序,因为如您所见,如果丢失了一些注释,这对用户来说不友好。

在lightbend/config中是否有可能实现这一点,或者是否有其他配置阅读器和写入器可以满足我的要求?

即使是除了HOCON之外的其他配置格式,只要有符合我要求的阅读器和写入器,我也可以使用。

由于我的配置要求比较复杂,属性文件可能不是一个很好的选择。

英文:

I am developing an application in java where it has a config file(I am choosing HOCON, if we have other option please let me know which meets my requirement ) and a UI for editing the config file.

Users can either edit the config file directly or can use the UI.
The config file can have comments.

If users are using UI to edit the file, I need to update the config file, when they hit save.

I am using lightbend/config for reading and writing the config file.

ConfigRenderOptions renderOpts = ConfigRenderOptions.defaults().setOriginComments(false).setJson(false);
	String writeString= tsConfig.root().render(renderOpts);

But the problem with the writing is it doesn't maintain the order of parameter and comments are messed up.
See the below image:

Do we have a proper serializable for HOCON which would respect the order or does a inline replacement in java?

My requirement is to have a writer which can maintain the comments and parameter order because as you can see it's not user friendly if some comments are lost .

Is it possible with lightbend/config or are there any other config reader &writer which can meet my requirement?

I am even ready to use other config formats other than HOCON, if we have a reader and writer which can meet my requirement.

As my config requirement is complex, property file would not be a great choice.

答案1

得分: 0

我找到了解决我自己问题的方法:

https://github.com/lightbend/config/issues/699

英文:

I found a solution for my own question:

https://github.com/lightbend/config/issues/699

huangapple
  • 本文由 发表于 2020年7月24日 03:04:23
  • 转载请务必保留本文链接:https://java.coder-hub.com/63061406.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定