swagger - 如何将 Swagger 的默认“响应内容类型”更改为“application/json”?
问题描述
SAP Commerce Cloud 版本:1905.9
目前,Swagger 的默认“响应内容类型”有 2 个值:“application/xml”和“application/json”。默认选择是“应用程序/xml”。有没有办法将默认选择更改为“application/json”?
示例香草代码是这样的:
@ApiOperation(hidden = true, value = "Updates the total amount of a specific product", notes = "Updates the total amount of a specific product in the cart based on the entryNumber.")
@RequestMappingOverride(priorityProperty = "b2bocc.CartResource.updateCartEntry.priority")
@RequestMapping(value = "/{cartId}/entries/{entryNumber}", method = RequestMethod.PUT)
@ResponseBody
@ApiBaseSiteIdUserIdAndCartIdParam
public CartModificationWsDTO updateCartEntry(@ApiParam(value = "Base site identifier.") @PathVariable final String baseSiteId,
@ApiParam(value = "The id of the entry in the cart.") @PathVariable final int entryNumber,
@ApiParam(value = "New quantity for this entry.") @RequestParam(required = true) final Long quantity,
@ApiParam(value = "Response configuration. This is the list of fields that should be returned in the response body.", allowableValues = "BASIC, DEFAULT, FULL") @RequestParam(required = false, defaultValue = FieldSetLevelHelper.DEFAULT_LEVEL) final String fields)
{
return updateCartEntry(baseSiteId, null, entryNumber, quantity, fields);
}
解决方案
您可以在springmvc-servlet.xml中切换转换器的顺序
<mvc:annotation-driven>
<mvc:message-converters>
<ref bean="jsonHttpMessageConverter"/>
<ref bean="xmlHttpMessageConverter"/>
<!-- <ref bean="customJsonHttpMessageConverter" /> -->
<!-- <ref bean="customXmlHttpMessageConverter" /> -->
</mvc:message-converters>
</mvc:annotation-driven>
推荐阅读
- typescript - 为什么不能在 TypeScript 中直接访问对象的属性?
- database - SQL 语句根据标识符获取时间范围内的所有条目
- python - Matplotlip - plotting many lines from dataframe in one graph
- vb.net - Get the name of the Parent of a child Panel
- javascript - Changes to localParticipant tracks do not propagate to remote participants when disabling webcam or microphone
- android - Error dagger missingBinding in Kotlin with dagger 2
- sql-server - Parallel merge strategy without deadlock
- java - Logging with prefix determined at a Class Initialization
- hibernate - InvalidDataAccessApiUsageException @OneToMany and @ManyToOne relationship
- php - 使用 php 和 httpclient 下载 githubarchive 数据