【发布时间】:2015-06-11 11:06:12
【问题描述】:
我已经使用 spring boot 创建了一个 REST 服务。最初我有多个参数(字符串和整数),但建议我以 json 格式发送请求并自动将其转换为对象。但是当我调用以下 REST 服务时,出现以下错误:
无法将类型“java.lang.String”的值转换为所需类型“x.x.x.MobileCreatives”
@RequestMapping(method = RequestMethod.POST, value = "/creative")
public @ResponseBody void uploadCreative(@RequestParam("mobileCreatives") MobileCreatives mobileCreatives,
@RequestParam("file") MultipartFile file){
logger.trace("Sending creative to DFP");
mobileCreatives.setFile(file);
dfpAssetsManager.createCreative(mobileCreatives);
}
我想知道为什么它认为输入是一个字符串,当输入是以下JSON时:
{"networkCode":6437988,"iO":"test345345","name":"test4354","advertiserId":11659988,"clickThroughUrl":"test.com"}
我的 MobileCreative 类有一个与 json 格式相同的构造函数。我是否需要向 MobileCreative 类添加任何注释,因为我正在查看的示例没有任何注释?
【问题讨论】:
-
试试 RequestBody MobileCreative movileCreative
标签: java json rest spring-boot