Paste Kotlin on the left and click "Convert" — we will turn it into XMLPaste Kotlin code

What this tool does

If you have ever had to hand-craft an XML payload for a Kotlin data class — for an Android resource file, a SOAP endpoint that still has not been replaced, or a fixture for an integration test — you know how tedious the typing is. Paste the Kotlin here and you get back well-formed XML in one pass. A single data class, a file with several data classes and sealed classes, or a populated val order = Order(...) instance — same result: a complete XML document with every property preserved.

It is not dumb string-replacement. The converter knows how Kotlin actually serialises to XML — roughly the way kotlinx.serialization handles things. BigDecimal values come out as plain numeric text, Instant and LocalDateTime become ISO-8601 strings, nullables with null values become empty elements, and List<T> and Map<K,V> follow a consistent container shape — each list becomes a wrapper element with one child per item, named after the element type.

Serialization annotations are honoured too. @SerialName("x") on a property renames the element in the output, @Transient drops the property, and a class-level @SerialName("x") renames the wrapping root element. Sealed class hierarchies are flattened with a type discriminator so you can round-trip them later. If you paste several data classes, each one lands in the output with nested types expanded and default values filled in. Full Kotlin serialization documentation is worth a read if you want the deep version.

How to use it

Three steps. Works the same whether you paste five lines or a full model file.

1

Paste your Kotlin (or try the sample)

Drop your Kotlin into the left editor as-is. A data class, a sealed class hierarchy, a populated val instance, or a file with multiple classes — all fine. Click Load Sample if you want to see a realistic example first.

You do not need to strip import statements, remove annotations, or clean up Kotlin syntax. Leave the code the way it looks in your IDE. Just paste.

2

Hit Convert

Click the green Convert button. The tool reads the Kotlin, preserves every class and property, and builds the XML in one pass. You will see a short loading indicator while it runs.

3

Copy the XML

The right panel fills with indented, well-formed XML that a standards-compliant XML parser will accept. Copy it straight into your Android resource, SOAP request, config file, or test fixture.

When this actually comes in handy

Android layout and resource XML

You have a Kotlin model that maps to an <a href="https://developer.android.com/guide/topics/resources/providing-resources" target="_blank" rel="noopener">Android XML resource</a> — a preferences screen, a string array, a custom attribute set. Paste the class, get the XML, paste it into res/xml or res/values.

SOAP clients on the JVM

A Kotlin request type needs to leave the app as SOAP. Paste the data class, drop the XML body into SoapUI or Postman, verify the contract without writing the envelope by hand.

Seeding test fixtures

Turn a populated <code>val order = Order(...)</code> instance from your unit test into an XML seed file for integration tests, mock servers, or legacy systems that still speak XML.

Keeping docs in sync

Generate XML examples for a README, an API reference, or XSD-backed schema docs directly from your actual Kotlin models, so the documentation matches the code instead of drifting from it.

Common questions

Can I paste multiple data classes at once?

Yes — paste a whole file. Each top-level data class or sealed class comes through with nested types expanded and default values filled in. Nothing is dropped silently.

Does it honour @SerialName and @Transient?

Yes. @SerialName("x") on a property renames the element in the output, @SerialName("x") on a class renames the wrapping root element, and @Transient drops the property entirely. That is the behaviour you get from kotlinx.serialization.

How does it handle BigDecimal, Instant, and nullables?

BigDecimal comes out as plain numeric text (no BigDecimal("...") wrapper). Instant and LocalDateTime become ISO-8601 strings. Nullables with a null value become empty elements rather than being dropped, so the shape stays consistent for consumers who validate against an XSD.

What about sealed classes, lists, and maps?

Sealed class hierarchies are flattened with a type discriminator attribute so you can round-trip them. List<T> becomes a container element with one child per item, named after the element type — a List<OrderItem> items turns into <items><OrderItem/><OrderItem/></items>. Map<K,V> becomes a container of <Entry><Key/><Value/></Entry>.

Is my code stored?

Your code is sent to the backend for conversion and is not persisted — we do not log the payload. As always with online tools, if the code is genuinely sensitive, look it over before pasting.

What if the Kotlin has something unusual — companion objects, extension functions, coroutines?

Companion objects are ignored for the XML output since they are not part of the instance state. Extension functions and top-level functions are skipped. If the code itself has syntax errors, fix the obvious ones first — the parser is forgiving but not psychic.

Other tools you may need

Kotlin to XML is one piece of the puzzle. These tools pair well with it: