I have a Spring controller that works great:
@RestController
@RequestMapping(value = "/widgets")
class WidgetController {
@RequestMapping(method = RequestMethod.POST)
WidgetResponse createWidget(@Valid @RequestBody Widget widget) {
// ...
}
}
Here I can POST a JSON message and my widget instance gets created:
{
"name" : "Widget1",
"type" : "spinning",
"isFizz" : true
}
I would like this endpoint to also accept and deserialize XML widgets like so:
<widget name="Widget1">
<type>spinning</type>
<isFizz>false</isFizz>
</widget>
I'm trying to figure out:
widgets.xsdAny ideas?
With the parameter consumes of annotation @RequestMapping
@RequestMapping(value = "/widgets",consumes={MediaType.APPLICATION_JSON_VALUE,MediaType.APPLICATION_XML_VALUE})
WidgetResponse createWidget(@Valid @RequestBody Widget widget){
///
{
The parameter consumes takes an array of MediaType
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With