Skip to content

Commit 0c9dfa2

Browse files
authored
Merge branch 'main' into feat/bump-palantir
2 parents 3c98662 + 9a1f849 commit 0c9dfa2

File tree

6 files changed

+38
-29
lines changed

6 files changed

+38
-29
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
2121
* **BREAKING** use `TrailingCommaManagementStrategy` enum instead of `manageTrailingCommas` boolean configuration option
2222
* Bump default `ktlint` version to latest `1.5.0` -> `1.7.1`. ([#2555](https://github.com/diffplug/spotless/pull/2555))
2323
* Bump default `palantir-java-format` version to latest `2.57.0` -> `2.71.0`.
24+
### Fixed
25+
* Fix `spaceBeforeSeparator` in Jackson formatter. ([#2103](https://github.com/diffplug/spotless/pull/2103))
2426
* `GitPrePushHookInstaller` uses a lock to run gracefully if it is called many times in parallel. ([#2570](https://github.com/diffplug/spotless/pull/2570))
2527

2628
## [3.3.1] - 2025-07-21

lib/src/jackson/java/com/diffplug/spotless/glue/json/JacksonJsonFormatterFunc.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2023 DiffPlug
2+
* Copyright 2021-2025 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
2323
import com.fasterxml.jackson.core.JsonGenerator;
2424
import com.fasterxml.jackson.core.util.DefaultIndenter;
2525
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
26-
import com.fasterxml.jackson.core.util.Separators;
2726

2827
import com.diffplug.spotless.FormatterFunc;
2928
import com.diffplug.spotless.json.JacksonJsonConfig;
@@ -88,23 +87,23 @@ protected static class SpotlessJsonPrettyPrinter extends DefaultPrettyPrinter {
8887

8988
public SpotlessJsonPrettyPrinter(boolean spaceBeforeSeparator) {
9089
this.spaceBeforeSeparator = spaceBeforeSeparator;
90+
91+
if (_objectFieldValueSeparatorWithSpaces == null || _objectFieldValueSeparatorWithSpaces.isEmpty()) {
92+
return;
93+
}
94+
95+
// Keep the behavior consistent even if Jackson changes default behavior
96+
boolean startsWithSpace = Character.isWhitespace(_objectFieldValueSeparatorWithSpaces.charAt(0));
97+
if (spaceBeforeSeparator && !startsWithSpace) {
98+
_objectFieldValueSeparatorWithSpaces = String.format(" %s", _objectFieldValueSeparatorWithSpaces);
99+
} else if (!spaceBeforeSeparator && startsWithSpace) {
100+
_objectFieldValueSeparatorWithSpaces = _objectFieldValueSeparatorWithSpaces.substring(1);
101+
}
91102
}
92103

93104
@Override
94105
public DefaultPrettyPrinter createInstance() {
95106
return new SpotlessJsonPrettyPrinter(spaceBeforeSeparator);
96107
}
97-
98-
@Override
99-
public DefaultPrettyPrinter withSeparators(Separators separators) {
100-
this._separators = separators;
101-
if (spaceBeforeSeparator) {
102-
// This is Jackson default behavior
103-
this._objectFieldValueSeparatorWithSpaces = " " + separators.getObjectFieldValueSeparator() + " ";
104-
} else {
105-
this._objectFieldValueSeparatorWithSpaces = separators.getObjectFieldValueSeparator() + " ";
106-
}
107-
return this;
108-
}
109108
}
110109
}

plugin-gradle/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1919

2020
### Fixed
2121
* Respect system gitconfig when performing git operations ([#2404](https://github.com/diffplug/spotless/issues/2404))
22+
* Fix `spaceBeforeSeparator` in Jackson formatter. ([#2103](https://github.com/diffplug/spotless/pull/2103))
2223
* `spotlessInstallGitPrePushHook` is now compatible with configuration cache. ([#2570](https://github.com/diffplug/spotless/pull/2570))
2324

2425
## [7.2.1] - 2025-07-21

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ public JacksonJsonGradleConfig jsonFeature(String feature, boolean toggle) {
168168
return this;
169169
}
170170

171+
public JacksonJsonGradleConfig setSpaceBeforeSeparator(boolean value) {
172+
jacksonConfig.setSpaceBeforeSeparator(value);
173+
return this;
174+
}
175+
171176
@Override
172177
public JacksonJsonGradleConfig self() {
173178
return this;

plugin-maven/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1515
* **BREAKING** use `TrailingCommaManagementStrategy` enum instead of `manageTrailingCommas` boolean configuration option
1616
* Bump default `ktlint` version to latest `1.5.0` -> `1.7.1`. ([#2555](https://github.com/diffplug/spotless/pull/2555))
1717
* Bump default `palantir-java-format` version to latest `2.57.0` -> `2.71.0`.
18+
### Fixed
19+
* Fix `spaceBeforeSeparator` in Jackson formatter. ([#2103](https://github.com/diffplug/spotless/pull/2103))
1820

1921
## [2.46.1] - 2025-07-21
2022
### Fixed
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
2-
"A" : 1,
3-
"X" : 2,
4-
"_arraysNotSorted" : [ 3, 2, 1 ],
5-
"_objectsInArraysAreSorted" : [ {
6-
"a" : 1,
7-
"b" : 2
2+
"A": 1,
3+
"X": 2,
4+
"_arraysNotSorted": [ 3, 2, 1 ],
5+
"_objectsInArraysAreSorted": [ {
6+
"a": 1,
7+
"b": 2
88
} ],
9-
"a" : 3,
10-
"c" : 4,
11-
"x" : 5,
12-
"z" : {
13-
"A" : 1,
14-
"X" : 2,
15-
"a" : 3,
16-
"c" : 4,
17-
"x" : 5
9+
"a": 3,
10+
"c": 4,
11+
"x": 5,
12+
"z": {
13+
"A": 1,
14+
"X": 2,
15+
"a": 3,
16+
"c": 4,
17+
"x": 5
1818
}
1919
}

0 commit comments

Comments
 (0)