I have created a REST service using spring boot. Initially I had multiple parameters (Strings and Ints), but it was suggested that I send the request in json and automatically convert it to an object. But when I call the following REST service I get the following error:
Failed to convert value of type 'java.lang.String' to required type '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);
}
I would like to know why it is thinking that the input is a string, when the input is the following JSON:
{"networkCode":6437988,"iO":"test345345","name":"test4354","advertiserId":11659988,"clickThroughUrl":"test.com"}
My class MobileCreative has a constructor that is in the same format as the json. Do I need to add any annotations to the class MobileCreative becasue an example I was looking at didn't have any?