Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save david-bakin/e0933e3a248c64e252605b25171f9764 to your computer and use it in GitHub Desktop.
Save david-bakin/e0933e3a248c64e252605b25171f9764 to your computer and use it in GitHub Desktop.
Jackson pretty printer that prints objects compactly (no whitespace) and array elements one-per-line
/* Looks like this:
{"todo":[
{"isbn":"0064632105"},
{"isbn":"007001115X"},
{"isbn":"0070079749"},
...
*/
public static class OneArrayElementPerLineNoWhitespacePrettyPrinter extends DefaultPrettyPrinter {
public OneArrayElementPerLineNoWhitespacePrettyPrinter() {}
public OneArrayElementPerLineNoWhitespacePrettyPrinter(@NonNull final DefaultPrettyPrinter source) {
super(source);
}
@Override
public DefaultPrettyPrinter createInstance() {
return new OneArrayElementPerLineNoWhitespacePrettyPrinter(this);
}
{
_arrayIndenter = new DefaultIndenter(" ", SYS_LF);
_objectIndenter = new NopIndenter() {
@Override
public boolean isInline() {
return false;
}
};
_spacesInObjectEntries = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment