FasterXML / jackson-dataformats-binary

Uber-project for standard Jackson binary format backends: avro, cbor, ion, protobuf, smile
Apache License 2.0
310 stars 133 forks source link

INDENT_OUTPUT for ION format? #337

Open didibus opened 2 years ago

didibus commented 2 years ago
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?

cowtowncoder commented 2 years ago

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?

mcliedtke commented 2 years ago

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

cowtowncoder commented 2 years ago

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).

didibus commented 2 years ago

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.