FasterXML / FasterXML/jackson-module-kotlin

XML: Support Kotlin's `object { ... }` as a List wrapper

Open
#415 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
1.2k
Forks
187
Avg merge
9h 48m
Merged PRs (30d)
16

Description

**Is your feature request related to a problem? Please describe.**
With Spring REST, I want to have this XML:


...

For that, I hoped I could use some very simple construct, like this:

object { @XmlWrapper val transactions = transactions }

But as you can see, I tried a lot, but the closest I got is `<>`
which is, I assume, due to an empty class name Jackson sees.

): ResponseEntity<*> {
val transactions = loadTransactions(filterType, filterValue)

val contentType = when(outputFormat) {
OutputFormat.JSON -> MediaType.APPLICATION_JSON
OutputFormat.XML -> MediaType.APPLICATION_XML
}
val body = when(outputFormat) {
OutputFormat.JSON -> transactions
//OutputFormat.XML -> transactions //
//OutputFormat.XML -> mapOf("transactions" to transactions) //
//OutputFormat.XML -> object { @field:JacksonXmlElementWrapper(name = "transactions") @field:XmlElementWrapper(name = "transactions") val transactions = transactions } // <>
//OutputFormat.XML -> object { @XmlElement(name = "transactions") val transactions = transactions } // <>
//OutputFormat.XML -> object { @field:XmlElement(name = "transactions") val transactions = transactions } // <>
OutputFormat.XML -> transactions(transactions) //
}
return ResponseEntity.status(HttpStatus.OK).contentType(contentType).body(body)

**Describe the solution you'd like**
Make this:

object { @field:XmlElementWrapper(name = "transactions") val transactions: List = transactions } /

produce this:


...
...

**Usage example**
See above - brief syntax for returning a List<...> from an endpoint.

**Additional context**

I didn't even manage to persuade Jackson to name the wrapper as I want using annotations.
It insisted on using the class name. So I had to rename it to `class transactions`.
But that's a different story.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.