UUID is a class that cannot be simply created. Assuming it comes as a request parameter, you should first annotate the argument with @RequestParam .
@RequestMapping("/MyController.myAction.mvc") @ResponseBody public String myAction(@RequestParam UUID id, String myParam)...
Now it expects that the request parameter with the name id will be available in the request. The parameter will be converted to a UUID . However, at the moment this will not succeed, because there is currently nothing that can convert from String to UUID .
To do this, create a Converter that can do this.
public class StringToUUIDConverter implements Converter<String, UUID> { public UUID convert(String source) { return UUID.fromString(source); } }
Connect this class to ConversionService , and you need to convert the UUID for the request parameters. (This will also work if it's a request header, mainly for everything that comes with ConversionService ). You can also have Converter for another path (UUID -> String).
By connecting it to Spring, MVC is well explained in the reference manual (assuming you are using xml config). But in a word:
<mvc:annotation-driven conversion-service="conversionService"/> <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"> <property name="converters"> <set> <bean class="org.company.converter.StringToUUIDConverter"/> </set> </property> </bean>
M. Deinum
source share