Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON formatting option "spaceBeforeSeparator" is ignored #929

Closed
dmak opened this issue Jul 30, 2024 · 2 comments
Closed

JSON formatting option "spaceBeforeSeparator" is ignored #929

dmak opened this issue Jul 30, 2024 · 2 comments
Labels
Milestone

Comments

@dmak
Copy link

dmak commented Jul 30, 2024

To Reproduce

Run mvn formatter:format on the attached project test.zip file. Expected that spaceBeforeSeparator=false configuration option in formatter-json.properties is honoured.

Other configuration options work just fine.

Versions (OS, Maven, Java, and others, as appropriate):

  • Affected version(s) of this project: 2.24.1
  • OS: Windows 10 x64

Additional information

Additionally I have run the test JsonFormatterTest.testDoFormatFileWithConfig() and at least in my setup it has generated the following JSON target\testoutput\someFile.json with spaces before field separator:

{
  "glossary" : {
    "GlossDiv" : {
      "GlossList" : {
        "GlossEntry" : {
          "Abbrev" : "ISO 8879:1986",
          "Acronym" : "SGML",
          "GlossDef" : {
            "GlossSeeAlso" : [
              "GML",
              "XML"
            ],
            "para" : "A meta-markup language, used to create markup languages such as DocBook."
          },
          "GlossSee" : "markup",
          "GlossTerm" : "Standard Generalized Markup Language",
          "ID" : "SGML",
          "SortAs" : "SGML"
        }
      },
      "title" : "S"
    },
    "title" : "example glossary"
  }
}

which is wrong because spaceBeforeSeparator=false:
image

I have noticed that overridden function DefaultPrettyPrinter#withSeparators(Separators separators) is not called, which means that _objectFieldValueSeparatorWithSpaces is left with default Jackson value :. This is because some of API has become deprecated in Jackson v2.17.
image

One of the solutions could be to initialize _objectFieldValueSeparatorWithSpaces directly in createInstance() as in fix.patch.

@dmak dmak added the bug label Jul 30, 2024
@ctubbsii
Copy link
Member

ctubbsii commented Aug 7, 2024

@dmak Thanks for the detailed explanation. Would you be able to open a PR with your proposed patch for easier review and merging?

dmak pushed a commit to dmak/formatter-maven-plugin that referenced this issue Aug 7, 2024
hazendaz added a commit that referenced this issue Aug 7, 2024
Adapt field separator initialization to Jackson v2.17 API (#929)
@hazendaz
Copy link
Member

hazendaz commented Aug 7, 2024

fixed via #930

@hazendaz hazendaz closed this as completed Aug 7, 2024
@ctubbsii ctubbsii added this to the 2.25.0 milestone Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants