-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Allow to configure line endings (and probably indentation) #585
Comments
I am guessing you are using default pretty printer (since by default Jackson does not add linefeeds). |
I tried that but I was unable to figure out how to make Jackson use my instance. Code from ObjectMapper.java:
final field -> no way to change it. Also, I couldn't figure out how to make ObjectMapper pass my preferred PrettyPrinter to JsonGenerator instances it creates. Instead, it calls useDefaultPrettyPrinter() which contains new DefaultPrettyPrinter(), so I can't override this as well. Lastly, I would have to copy the whole class Lf2SpacesIndenter since it's hostile to any kind of reuse. To add insult to injury, my Eclipse refuses to open GeneratorBase :-( Would you accept a pull request? |
Ah, no, don't try to change definition of default pretty-printing; rather, assign your own You should not have to change anything in |
Suggestion for the indenter:
|
Can you please provide an example how to configure |
You will need to use
and either hold on to writer, or just create instances dynamically; they are cheap to create unlike Use of |
Sent you a pull request for the new DefaultIndenter above: FasterXML/jackson-core#166 |
Interesting discussion... I know this issue is already closed but it still sounds like a bug to me. I use the So I would like to add my own custom |
@derknorton what sounds like a bug? Pull request #166 was merged, included in 2.5.0. As to semantics, while it's not a huge deal, missing functionality is not a bug, but, well, missing functionality. Creating a new issue for adding things that are missing and you would like to see is perfectly fine; and in fact I prefer it over re-opening old issues (unless it is specific flaw in fix/addition itself). |
Summary:This upgrade was motivated by the need to pick up the fix for FasterXML/jackson-databind#585. Basically, we want to make sure that `BUCK.autodeps` files are byte-for-byte identical, regardless of whether it is run on Windows or non-Windows. As such, we need to be able to specfiy the line endings used by the Jackson pretty-printer. After downloading the appropriate JARs from Maven, and replacing them in third-party, I ran the following commands to help create this change: ``` git grep -l jackson-annotations-2.0.5 | xargs sed -i '' -e 's#jackson-annotations-2.0.5#jackson-annotations-2.5.5#g' git grep -l jackson-core-2.0.5 | xargs sed -i '' -e 's#jackson-core-2.0.5#jackson-core-2.5.5#g' git grep -l jackson-databind-2.0.5 | xargs sed -i '' -e 's#jackson-databind-2.0.5#jackson-databind-2.5.5#g' ``` After that, I had to fix up a bunch of Jackson API calls because some of them had become deprecated in favor of new methods. The existing JSON pretty printer that we were using in `AutodepsWriter` was one such deprecation, so I fixed the line-ending issue while there. Test Plan:* Ran `buck autodeps` and verified that no `BUCK.autodeps` files changed. * CI Reviewed By: sdwilsh fb-gh-sync-id: eec12c6 shipit-source-id: eec12c6
Realise this ticket is closed, but we faced a similar issue when matching messages in unit tests on Windows machines. So adding this here for others who stumble upon this page. The The line-feed char can be set as follows:
|
When writing multi-OS unit tests, it's cumbersome to filter the line endings from Jackson's output.
Please add a config option which allows to configure the line endings to use (and maybe the indentation level or String) so I can write unit tests which always produce a single Line Feed.
If I could configure the indentation, that would allow me to use tabs or four spaces to indent.
The text was updated successfully, but these errors were encountered: