<p>I need to pass a UUID instance via http request parameter. Spring needs a custom type converter (from String) to be registered. How do I register one?</p>

[{'answer_id': 68035, 'author': 'toolkit', 'author_id': 3295, 'author_profile': 'https://Stackoverflow.com/users/3295', 'pm_score': 0, 'selected': False, 'text': '<p>Not sure what you are asking?</p>\n\n<p>Spring comes with a <a href="http://static.springframework.org/spring/docs/2.5.5/api/org/springframework/beans/factory/config/CustomEditorConfigurer.html" rel="nofollow noreferrer">CustomEditorConfigurer</a> to supply custom String &lt;-> Object converters.</p>\n\n<p>To use this, just add the CustomEditorConfigurer as bean to your config, and add the custom converters. However, these converters are typically used when converting string attributes in the config file into real objects.</p>\n\n<p>If you are using Spring MVC, then take a look at the section on <a href="http://static.springframework.org/spring/docs/2.5.5/reference/mvc.html#mvc-annotation" rel="nofollow noreferrer">annotated MVC</a></p>\n\n<p>Specifically, have a look at the <strong>@RequestParam</strong> and the <strong>@ModelAttribute</strong> annotations?</p>\n\n<p>Hope this helps? </p>\n'}, {'answer_id': 68450, 'author': 'MetroidFan2002', 'author_id': 8026, 'author_profile': 'https://Stackoverflow.com/users/8026', 'pm_score': 2, 'selected': False, 'text': '<p>Please see chapter 5 of the spring reference manual here: <a href="http://static.springframework.org/spring/docs/2.5.x/reference/validation.html#beans-beans-conversion-customeditor-registration" rel="nofollow noreferrer">5.4.2.1. Registering additional custom PropertyEditors</a></p>\n'}, {'answer_id': 69314, 'author': 'alexei.vidmich', 'author_id': 7199, 'author_profile': 'https://Stackoverflow.com/users/7199', 'pm_score': 2, 'selected': False, 'text': '<p>I have an MVC controller with RequestMapping annotations. One method has a parameter of type UUID.\nThanks toolkit, after reading about <a href="http://static.springframework.org/spring/docs/2.5.5/reference/mvc.html#mvc-ann-webdatabinder" rel="nofollow noreferrer">WebDataBinder</a>, I figured that I need a method like this in my controller:</p>\n\n<pre><code>@InitBinder\npublic void initBinder(WebDataBinder binder) {\n    binder.registerCustomEditor(UUID.class, new UUIDEditor());\n}\n</code></pre>\n\n<p>UUIDEditor simply extends PropertyEditorSupport and overrides getAsText() and setAsText().</p>\n\n<p>Worked for me nicely.</p>\n'}, {'answer_id': 1555102, 'author': 'David Newcomb', 'author_id': 52070, 'author_profile': 'https://Stackoverflow.com/users/52070', 'pm_score': 2, 'selected': False, 'text': '<p>In extenstion to the previous example.</p>\n\n<p>Controller class</p>\n\n<pre><code>@Controller\n@RequestMapping("/showuuid.html")\npublic class ShowUUIDController\n{\n\n  @InitBinder\n  public void initBinder(WebDataBinder binder)\n  {\n    binder.registerCustomEditor(UUID.class, new UUIDEditor());\n  }\n\n  public String showuuidHandler (@RequestParam("id") UUID id, Model model)\n  {\n    model.addAttribute ("id", id) ;\n    return "showuuid" ;\n  }\n}\n</code></pre>\n\n<p>Property de-munger</p>\n\n<pre><code>class UUIDEditor extends java.beans.PropertyEditorSupport\n{\n\n  @Override\n  public String getAsText ()\n  {\n    UUID u = (UUID) getValue () ;\n    return u.toString () ;\n  }\n\n  @Override\n  public void setAsText (String s)\n  {\n    setValue (UUID.fromString (s)) ;\n  }\n\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/67980', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7199/']