Repository navigation
Conversation
…with comments The jacksonJson step could only toggle SerializationFeature and JsonGenerator.Feature, so a JSON file with comments always failed with "Unable to format" and there was no way to accept them (issues/2271). Adds jsonParserFeatureToToggle to JacksonJsonConfig, applied to the JsonFactory like the existing generator features; exposed as jsonParserFeature(feature, toggle) in the Gradle extension and as <jsonParserFeatures> in the Maven plugin. Note that Jackson parses comments and then drops them, so formatting no longer fails but the comments themselves are not preserved - the new test documents that. Fixes diffplug#2271
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
jacksonJsonstep could toggleSerializationFeature(feature) andJsonGenerator.Feature(jsonFeature), but notJsonParser.Feature. A JSON file containing comments therefore always failed withUnable to format, and there was no way to accept them. Fixes #2271.What changed
JacksonJsonConfig: newjsonParserFeatureToTogglemap (getter / setter / append), mirroring the existingjsonFeatureToToggle.JacksonJsonFormatterFunc: applies the parser features to theJsonFactoryright after the generator features.jsonParserFeature(String feature, boolean toggle)on thejacksonJsonconfig.<jsonParserFeatures>map on<jackson>.Behavior note
Jackson parses the comments and then drops them, so formatting no longer fails but the comments themselves are not preserved. The new test documents exactly that (per the discussion in #2272), so the behavior is explicit rather than surprising.
What must NOT change
feature/jsonFeature/spaceBeforeSeparatoroptions and their defaults are untouched.jsonParserFeatureconfigured, output is byte-for-byte identical to before (the new map is empty by default); all existingJacksonJsonStepTest,JsonSimpleStepTestandGsonStepTestcases pass unchanged.Verification
IllegalArgumentException: Unable to format(reproduced onmain).canSetJsonParserFeaturepasses; the wholecom.diffplug.spotless.jsonpackage passes (20 tests, 0 failures).spotlessApplyrun, and:plugin-gradle:compileJava/:plugin-maven:compileJavaare clean.This revives the intent of #2272 with the test, changelog and docs entries requested there.