config icon indicating copy to clipboard operation
config copied to clipboard

Question: Do we have a proper serializable for HOCON which would respect the order or does a inline replacement

Open ankkumar-progress opened this issue 4 years ago • 6 comments

I am developing an application 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:

image

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 to 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.

ankkumar-progress avatar Jul 23 '20 18:07 ankkumar-progress

See #453, #300 ... the ConfigDocument API would support load/edit/save, rather than trying to make ConfigObject do this. But the ConfigDocument API is very incomplete and needs effort.

havocp avatar Jul 23 '20 19:07 havocp

Thanks for the help This is what I was looking for.

A very vague question, even if you don't' have an answer it's fine

Q: Can we use ConfigDocument and ConfigDocumentFactory for a groovy configuration file? We would only use the ConfigDocument for reading and writing and not for resolving the value because it is obvious we have to run it and ConfigDocument doesn't support.

There is a reader/resolver for a groovy configuration file called ConfigSlurper but we don't' have a writer for it. And due to some reason, we are also not supporting expression or method, and the file would be pretty similar to HOCON.

As I already told the question is a little vague but it would be very helpful if you give your opinion on it.

ankkumar-progress avatar Jul 29 '20 07:07 ankkumar-progress

It looks like there are some incompatibilities with ConfigSlurper (for example single quotes vs double, but probably other details too). So if your goal is to be compatible with groovy config files I don’t think you could accomplish that.

havocp avatar Jul 29 '20 12:07 havocp

Say for instance I added a constraint to the user to use only double quotes in groovy config. I know that's a little weird but let's assume that.

What would be other complications as you mentioned "other details"?

The reason as I am insisting because in the future we will completely move to HOCON or Groovy config. But for now, we are in middle of the transition, so just want to be aware of the consequences.

I know a weird requirement , please bear with me.

ankkumar-progress avatar Jul 29 '20 13:07 ankkumar-progress

I don’t know the details of the groovy syntax, but basically I’d expect there are a variety of small differences so the config file writer would have to carefully consider the intersection of the two formats.

havocp avatar Jul 29 '20 14:07 havocp

Thanks for the reply I really appreciate for replying in no time.

ankkumar-progress avatar Jul 29 '20 20:07 ankkumar-progress