Kotlin to XML Converter

Paste Kotlin data classes or an instance. Get clean XML back.

Input

Output

Paste your Kotlin code on the left and press Convert.

Or drop a file on this box, , or .

What this tool does

Kotlin projects run into XML more often than people expect: Android resource files, a JVM SOAP endpoint nobody has retired, a fixture for an old partner API. Typing that XML out for a Kotlin data class is slow and easy to get wrong. Paste the class here, or a filled-in val order = Order(...), and the page gives you XML that mirrors it, including nested classes and lists.

Types are mapped roughly the way kotlinx.serialization would treat them. A BigDecimal prints as the bare number, Instant and LocalDateTime as ISO-8601 text, and a nullable property set to null stays in the document as an empty tag. The sample's items: List<OrderItem> becomes an <items> element with an <OrderItem> inside for each line, and string-keyed maps turn into a set of key/value entries.

@SerialName is respected, as you can see in the sample, where orderId is written out as <OrderId>. On a class it renames the root element, and @Transient removes a property from the output. A sealed class instance takes the name of its concrete subclass, so a PaymentMethod.Card value shows up as <Card>. The Kotlin serialization guide covers the real library if you plan to do this at runtime.

How to use it

Paste a data class, hit Convert, copy the result. Whether it is one small class or a whole model package file, the steps do not change.

1

Paste your Kotlin (or try the sample)

Paste Kotlin into the left editor: a data class, a sealed class family, a constructed val instance, or a file with several classes. Load Sample gives you an @Serializable Order with a BigDecimal total and two line items.

Imports, KDoc and annotations are fine to leave in. Named constructor arguments, as in Order(orderId = "ORD-4821", ...), help because the names line up with the elements; plain positional arguments work as long as the class is in the paste too. The Kotlin reference has the full syntax if you need it.

2

Hit Convert

Press the green Convert button. The Kotlin is sent to the backend, which matches constructor arguments to properties, applies @SerialName and replies with the XML. A "Converting..." overlay covers the page until the reply lands.

3

Copy the XML

The right pane shows the finished document, indented by two spaces and starting with an XML declaration. It is read-only, so select all and copy it into an Android res/xml file, a SOAP body, or a test resource.

When this actually comes in handy

Android layout and resource XML

You have a Kotlin model that maps to an Android XML resource: 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

The val order = Order(...) you already built in a unit test can become an XML seed file for an integration test, a stub server or an older system that only accepts 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 the whole file. Every top-level data class and sealed class is read, nested classes are expanded where they are used, and properties with default values like val currency: String = "EUR" appear with that default when the instance does not override it.

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?

A BigDecimal becomes plain numeric text, without a BigDecimal("...") wrapper. Instant and LocalDateTime turn into ISO-8601 strings. When a String? or Int? holds null, its element is still written with no content, which keeps the document stable for consumers validating against an XSD.

What about sealed classes, lists, and maps?

Each sealed class value gets an element carrying its subclass name, with that subclass's properties inside, for example <Card><last4>4242</last4></Card>. Lists and sets get a wrapper named after the property, and each entry inside takes the element type's name, or Item for things like List<Int>. Map<String, V> becomes a group of <Entry> children, each holding a key and a value.

Is my code stored?

A request carrying your Kotlin goes to the backend and the generated XML is the only thing returned. We do not store it, and nothing is cached in your browser either. If the code is under NDA, paste only the data classes. Repositories, ViewModels and coroutine code are not needed for the conversion.

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

Companion objects are not part of an instance, so they are left out. Extension functions, top-level functions and suspend code are skipped as well. If the result looks incomplete, make sure the snippet compiles: an unclosed parenthesis in a long constructor call is the usual culprit.

Other tools you may need

These pages are handy after a Kotlin conversion, whether you want to validate the XML, generate Kotlin from an XML sample, or get JSON for the same data class: