jackson-dataformats-binary icon indicating copy to clipboard operation
jackson-dataformats-binary copied to clipboard

INDENT_OUTPUT for ION format?

Open didibus opened this issue 3 years ago • 4 comments

IonObjectMapper om = new IonObjectMapper();
om.enable(SerializationFeature.INDENT_OUTPUT);
om.writeValueAsString(object)

Doesn't seem to work with an IonObjectMapper the way it does with the JSON ObjectMapper, any way to accomplish the same?

didibus avatar Aug 30 '22 03:08 didibus

Ion backend would need to support this. I think Ion textual format does have the functionality. Did you test with latest (2.13.3) version?

cowtowncoder avatar Aug 30 '22 20:08 cowtowncoder

Ion backend does support "pretty printing" Ion text, they have some documentation on it here - https://amzn.github.io/ion-docs/guides/cookbook.html#pretty-printing.

It might be down to customizing the IonWriter being used to produce the Text output based on the feature flag.

In the meantime, you could be unblocked by using IonObjectMapper.writeValueAsIonValue to output to an IonValue and then pretty-print that value using the IonWriter methods referenced in the link

mcliedtke avatar Aug 30 '22 22:08 mcliedtke

Thank you @mcliedtke!

It sounds like this feature could well be implemented by someone with time on their hands. In the meantime I think IonMapper might have additional writeValue() methods that could take properly initialized IonWriter (not 100% sure as I didn't check but I think it does have some extensions to main ObjectMapper API).

cowtowncoder avatar Aug 30 '22 22:08 cowtowncoder

In the meantime, you could be unblocked by using IonObjectMapper.writeValueAsIonValue to output to an IonValue and then pretty-print that value using the IonWriter methods referenced in the link

I did this for now, and it worked.

didibus avatar Aug 30 '22 23:08 didibus