Scala to XML Converter

Paste Scala case classes or objects. Get clean XML back.

Input

Output

Paste your Scala code on the left and press Convert.

Or drop a file on this box, , or .

What this tool does

If you have ever needed an XML payload that matches a Scala case class (for an Akka HTTP fixture, a Play Framework config, a legacy SOAP integration, or a test) you have probably hand-written more XML than you wanted to. Paste the Scala here and get back well-formed XML straight away. A single case class, a populated val, or a whole file with nested types: all of it comes through with every field preserved.

Scala types are mapped to text with some care. BigDecimal("249.99") is written as 249.99, java.time values become ISO-8601 strings, and an Option[String] unwraps Some("gift wrap") to its text or leaves an empty element for None. List, Seq, Vector and Set fields get a wrapper with an element for each member named after its type, while a Map[String, V] turns into <Entry> pairs. If your code already contains native XML literals in the style of scala-xml, that shape is kept, and Jackson-style annotations from jackson-module-scala are taken into account.

Nested case classes expand into nested elements, companion-object constants are ignored, and sealed-trait hierarchies keep the concrete subtype name as the element tag. You can paste several classes at once: the converter preserves the relationships, so if your Order contains a List[OrderItem] and a ShippingAddress, all three come back together. See the official case class tour for a refresher on what gets treated as data vs behaviour.

How to use it

Paste a model file, convert, copy. Here is what to expect from Scala at each step.

1

Paste your Scala (or load the sample)

Paste the code into the left editor. Case classes on their own work, but you get real values only when there is a val order = Order(...) as well. Load Sample shows that combination: three case classes, BigDecimal prices, a notes = None field and a List of two items.

Imports, the package clause, companion objects and derives clauses are fine to leave in; see the Scala docs if any of the syntax is new to you. Scala 2 and Scala 3 syntax both read the same for this purpose.

2

Hit Convert

Hit the green Convert button. Our backend receives the source, pairs the named arguments of your val with the case class fields and replies with XML. There is no compilation step, and the panes show "Converting..." until the reply is in.

3

Copy the XML

The XML arrives on the right, indented by two spaces and opening with an XML declaration. Use it as the expected body in an Akka HTTP or http4s route test, or load it with scala.xml.XML.loadString to be sure it parses.

When this actually comes in handy

Akka HTTP and Play fixtures

You have a case class for an inbound XML request in Akka HTTP or Play and need a realistic body for a test or a curl command. Paste the class, get the XML, drop it into your spec.

XML config for legacy systems

A Typesafe Config or PureConfig case class with dozens of settings can be turned into an XML template for a platform that still reads XML config, such as Mule, WebLogic or IBM MQ.

Documentation that matches the code

Put an XML example generated from the real case class into the README or the ScalaDoc for a service, so readers see the payload that matches the code they are looking at.

Test data for SOAP and scala-xml

Turn populated instances from your unit tests into XML seed files for integration tests, WireMock stubs, or systems that still speak SOAP.

Common questions

Can I paste multiple case classes at once?

Yes, within the 64 KB limit of the backend. If the paste contains a populated val, that value becomes the document and the case classes it uses are nested inside it, so Order with a List[OrderItem] produces both levels. With only definitions, the converter fills fields with defaults (empty strings, 0, false) and wraps unrelated top-level classes in a single <Root> element.

How does it handle Option, None, and default values?

An Option[String] holding Some("x") becomes a normal element with the text inside. None becomes an empty element so the shape of the XML stays consistent: nothing gets silently dropped. Default values on case class fields are used when a field is missing from the instance.

What about BigDecimal, Instant, UUID, and the funky numeric types?

BigDecimal drops its suffix and comes out as plain numeric text. java.time.Instant, LocalDate, and LocalDateTime become ISO-8601 strings. UUID keeps its standard 8-4-4-4-12 hex format. Primitive wrappers (Int, Long, Double, Boolean) become plain text: the same shape jackson-module-scala emits by default.

Do List, Seq, Set, and Map all work the same way?

The sequence types behave alike: List, Seq, Vector and Set become a wrapper named after the field, and items: List[OrderItem] therefore produces an items element containing one OrderItem per list element. A Map[String, V] is different: each pair is written as <Entry> with <Key> and <Value> children. For an Either, whichever side holds the value is written, and a sealed trait member is wrapped in an element named after its subclass.

Is my code stored?

Convert hands the Scala source to our backend for one conversion and gets the XML back; nothing is stored by the site. Watch for application.conf snippets with passwords or real customer data in a test fixture and replace them before pasting.

What if the Scala has implicit conversions, type classes, or macros?

Implicits, givens and macros generate behaviour at compile time, and nothing is compiled here, so they add no fields; an implicit val format or a @JsonCodec annotation is simply passed over and the plain case class fields are what you see. A field whose value comes from a method call cannot be computed either, so use a literal in the val if you need it filled. If sbt would reject the snippet, fix the syntax first.

Other tools you may need

After the case class is in XML form, you may want the JSON version as well, or to read and validate the result: