jackson-databind icon indicating copy to clipboard operation
jackson-databind copied to clipboard

Support prettifying of serializing json string with f.ex key and value different color

Open hafiz013 opened this issue 2 years ago • 3 comments

If this library possible in the future make key and value of json beauty different color like in apps postman.

hafiz013 avatar Jun 01 '22 09:06 hafiz013

jackson is not responsible for syntax highlighting of output.

yawkat avatar Jun 01 '22 09:06 yawkat

Agree with @yawkat: such functionality would need to be done by some other tool, or by Jackson extension. I assume this would require adding terminal emulation characters (VT-100 etc) around content; something that "JSONP" style wrappers can do.

In fact I suspect this might be already doable, come to think of that, but my terminal emulation code knowledge is bit dated (I did write a Java terminal emulator once, but that was in late 1990s!).

Although... given that this is asking for separate styling for key and values, I think the combination to use would have to be something like:

  • Use custom PrettyPrinter to inject terminal emulation codes
  • Use JsonGenerator.writeRaw() for actual forced writes of codes, outside of "regular" content itself

but I do think that is actually doable.

And... it sounds like someone could maybe create a Jackson Module that allows doing this, with configurability of styling to use.

cowtowncoder avatar Jun 01 '22 17:06 cowtowncoder

I just image if can do it.

hafiz013 avatar Jun 09 '22 07:06 hafiz013