FasterXML / FasterXML/jackson-module-kotlin
XML: Support Kotlin's `object { ... }` as a List wrapper
- Lingua principale
- Kotlin
- Stelle
- 1.2k
- Fork
- 187
- Merge medio
- 9h 48m
- PR unite (30g)
- 16
Descrizione
**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.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.