There are numerous Scala libraries to convert arbitrary objects to JSON and a few to convert JSON to XML, but I can't seem to find a nice way to convert arbitrary objects to XML. What's a good approach?
I used scalaxb a while ago. It works very well if you have an XSD (or WSDL) as input to generate your classes. If this is the case, I also recommend using it.
Since you're also talking about JSON it may be that you have a web application using REST. In this case, have a look at Lift's REST-Support. For instance, if you use one of its internal persistency frameworks then all your entity types get a toXML
method for free.
A third possibility would be to write your own conversion using Scala's XML literals.
Btw possible duplicates on Stack Overflow: Scala XML serialization and Which XML serialization library for Scala?
Check this project: https://github.com/geirolz/advxml
It's a simple library based on RuleTransformer(standard scala xml library) and Cats with the aim to simplify the XML transformation and serialization/deserialization.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With