Spin: disable pretty printing

Hey there,

we are using Spin to store XML objects in the execution variable. The problem is the output of Spin elements via element.toString or element.writeToWriter because the output is always pretty printed with lots of new lines and indents, which is something we do not want. I found the reason for this in the DomXmlDataFormatWriter-Class, specifically in the getTransformer-method where the transformer is configured to use indents.

According to this, I tried configuring the existing data format (DomXmlDataFormat) with a DataFormatConfigurator but cannot find a suitable method to override the specific method.

I also tried to create a custom datatype where I extend the existing DomXmlDataFormat and just override the getTransformer-method but this also did not work and it seems a bit overload for achieving such a simple task.

Is there a way to override the getTransformer-method with a DataFormatConfigurator? Or any other way I can disable the pretty printing when working with Spin?

Is the question too specific? Did I express my problem poorly?

Hi @Matthias_Dietl,

Sorry for the late response. I understand your concern. Looks like the class DomXmlDataFormat is missing a setter for the writer field to be able to exchange the writer easily. Workarounds that come to mind are:

  • Add your configurator to the same package as DomXmlDataFormat and benefit from writer being protected. Quick and dirty :slight_smile:
  • Instead of creating a DataFormatConfigurator, implement DataFormatProvider and let it behave like DomXmlDataFormatProvider but return a custom subclass of DomXmlDataFormat with an appropriate writer. Then make sure that the default provider won’t be looked up. Certainly cleaner, but more effort.

Also, feel free to submit a pull request to https://github.com/camunda/camunda-spin to make configuration of the writer easier.

Cheers,
Thorben

Hey @thorben,

thank you for your reply. Option 2 seems to be the way to go. Could you give me a hint on how to make sure the default provider won’t be looked up?

Thanks,
Matthias

DataFormatProvider implementations are found at runtime via the Java ServiceLoader infrastructure. The DomXmlDataFormatProvider is therefore declared in META-INF/services/org.camunda.spin.spi.DataFormatProvider file of the spin xml dataformat artifact.

You could remove that file (e.g. via Maven). If you are in JBoss/Wildfly and as an alternative, you could declare that a dependency to the xml data format module does not import the declared services. When you use Spin in combination with the process engine, you would have to edit the module descriptor of the spin process engine plugin for that purpose.

I hope that helps.

Cheers,
Thorben