mORMot2 icon indicating copy to clipboard operation
mORMot2 copied to clipboard

Feature Request: ObjectToIni() output set types as CSV format

Open zen010101 opened this issue 4 months ago • 4 comments

Regarding commit 6d77e94b, IniToObject() now supports reading set types in CSV format (e.g., Methods=get,head), which is very convenient and more readable than JSON arrays.

However, I noticed that ObjectToIni() still outputs set types in JSON array format: LogLevels=["Info","Warning","Error","Custom1"]

Instead of the cleaner CSV format: LogLevels=Info,Warning,Error,Custom1

Would it be possible to have ObjectToIni() output set types in CSV format as well? This would make TSynJsonFileSettings.SaveIfNeeded produce INI files with consistent read/write format, and the resulting files would be more human-friendly to edit.

zen010101 avatar Dec 12 '25 10:12 zen010101

Please try with today's commit.

ObjectToIni() should be paired with IniToObject() unserialization level now. As paired with those tests.

synopse avatar Dec 12 '25 17:12 synopse

Thank you for the quick implementation! I've pulled the latest commits and verified the changes. Everything works perfectly now.

Test Results:

  1. ObjectToIni now outputs CSV format for sets: LogLevels=Info,Warning,Error,Exception,Custom1
  2. Instead of the previous JSON array format ["Info","Warning",...]
  3. Round-trip test passed: - Original: LogLevels=[Info,Warning,Error,Exception,Custom1] - Saved via ObjectToIni: LogLevels=Info,Warning,Error,Exception,Custom1 - Loaded via IniToObject: LogLevels=[Info,Warning,Error,Exception,Custom1] - ✅ Round-trip OK: TRUE
  4. Both read formats still work: - CSV format: LogLevels=Info,Warning,Error ✅ - JSON format: LogLevels=["Info","Warning","Error"] ✅

The new TIniFeatures parameter and the refactored ObjectToIni implementation provide a clean, consistent read/write experience. The optional woHumanReadableEnumSetAsComment producing a values comment is a nice touch for human-editable config files.

Great work! 👍

zen010101 avatar Dec 13 '25 04:12 zen010101

I noticed that when using TSynJsonFileSettings with fsoWriteIni, the output now includes helpful comments showing all possible enum/set values:

[Main] ; values=None,Info,Debug,Trace,Warning,Error,... LogLevels=Info,Warning,Error,Custom1

While this is useful for documentation purposes, in some production scenarios we prefer cleaner config files without these comments.

Suggestion: Add a new option like fsoNoEnumSetComment in TFileSettingsOptions to allow disabling the woHumanReadableEnumSetAsComment behavior when saving INI files.

Currently, the workaround is to override SaveIfNeeded, but a built-in option would be cleaner:

TFileSettingsOptions = set of ( fsoDisableSaveIfNeeded, fsoReadIni, fsoWriteIni, fsoNoEnumSetComment // New option to disable enum/set comments );

Then in SaveIfNeeded: if fsoWriteIni in fSettingsOptions then if fsoNoEnumSetComment in fSettingsOptions then saved := ObjectToIni(self, fSectionName, [woEnumSetsAsText, woRawBlobAsBase64]) else saved := ObjectToIni(self, fSectionName);

Thank you for considering this enhancement!

zen010101 avatar Dec 13 '25 04:12 zen010101

Good idea.

See above.

synopse avatar Dec 13 '25 09:12 synopse

Confirm! It works perfectly.

zen010101 avatar Dec 14 '25 16:12 zen010101