Josh
Josh

Reputation: 875

Convert Scala object to XML

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?

Upvotes: 8

Views: 4754

Answers (3)

David Geirola
David Geirola

Reputation: 632

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.

Upvotes: 1

Silas
Silas

Reputation: 1150

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?

Upvotes: 3

Alex Cruise
Alex Cruise

Reputation: 7979

scalaxb looks decent, I'd try that first.

Upvotes: 0

Related Questions