FasterXML / FasterXML/jackson-module-kotlin

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

Offen
#415 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Kotlin
Sterne
1.2k
Forks
187
Ø Merge
9 Std. 48 Min.
Gemergte PRs (30 T.)
16

Beschreibung

**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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.