{"id":3673,"date":"2011-04-15T00:48:30","date_gmt":"2011-04-14T19:18:30","guid":{"rendered":"https:\/\/tothenewco.pro\/blog\/?p=3673"},"modified":"2022-01-12T19:33:57","modified_gmt":"2022-01-12T14:03:57","slug":"groovy-few-ways-to-convert-string-into-enum","status":"publish","type":"post","link":"https:\/\/tothenewco.pro\/blog\/groovy-few-ways-to-convert-string-into-enum\/","title":{"rendered":"Groovy: Few ways to convert string into enum"},"content":{"rendered":"<p>Many at times, we have a string which needs to be converted into Enum. I will be sharing few options as stated by <a href=\"http:\/\/mrhaki.blogspot.com\/2010\/12\/groovy-goodness-transform-string-into.html\">Mr.Haki<\/a>, Isa Goksu and in the last the one I discovered during the process.\u00a0Lets say we have a Enum AccountType as given below :<\/p>\n<p>[groovy]<\/p>\n<p>enum AccountType {<br \/>\n     CHECKING,<br \/>\n     SAVING<br \/>\n}<\/p>\n<p>assert AccountType.CHECKING == &amp;quot;CHECKING&amp;quot; as AccountType<\/p>\n<p>assert AccountType.CHECKING == AccountType.valueOf(&amp;quot;CHECKING&amp;quot;)<br \/>\ndef className = AccountType.class<br \/>\nassert AccountType.CHECKING == Enum.valueOf(className, &amp;quot;CHECKING&amp;quot;)<\/p>\n<p>assert AccountType.CHECKING == AccountType[&amp;quot;CHECKING&amp;quot;]<br \/>\nString type = &amp;quot;CHECKING&amp;quot;<br \/>\nassert AccountType.CHECKING == AccountType[type]<\/p>\n<p>[\/groovy]<\/p>\n<p>Cheers!<br \/>\n~~Amit Jain~~<br \/>\namit@intelligrape.com<br \/>\nhttps:\/\/tothenewco.pro<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many at times, we have a string which needs to be converted into Enum. I will be sharing few options as stated by Mr.Haki, Isa Goksu and in the last the one I discovered during the process.\u00a0Lets say we have a Enum AccountType as given below : [groovy] enum AccountType { CHECKING, SAVING } assert [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":71,"footnotes":""},"categories":[7],"tags":[557,555,9,556],"class_list":["post-3673","post","type-post","status-publish","format-standard","hentry","category-grails","tag-convert-string-to-enum","tag-enum","tag-groovy","tag-transform-string-to-enum"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Many at times, we have a string which needs to be converted into Enum. I will be sharing few options as stated by Mr.Haki\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Amit Jain\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/tothenewco.pro\/blog\/groovy-few-ways-to-convert-string-into-enum\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Groovy: Few ways to convert string into enum | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Many at times, we have a string which needs to be converted into Enum. I will be sharing few options as stated by Mr.Haki\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/tothenewco.pro\/blog\/groovy-few-ways-to-convert-string-into-enum\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/tothenewco.pro\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/tothenewco.pro\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Groovy: Few ways to convert string into enum | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Many at times, we have a string which needs to be converted into Enum. I will be sharing few options as stated by Mr.Haki\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/tothenewco.pro\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/groovy-few-ways-to-convert-string-into-enum\\\/#article\",\"name\":\"Groovy: Few ways to convert string into enum | TO THE NEW Blog\",\"headline\":\"Groovy: Few ways to convert string into enum\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/amit\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2011-04-15T00:48:30+05:30\",\"dateModified\":\"2022-01-12T19:33:57+05:30\",\"inLanguage\":\"en-US\",\"commentCount\":2,\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/groovy-few-ways-to-convert-string-into-enum\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/groovy-few-ways-to-convert-string-into-enum\\\/#webpage\"},\"articleSection\":\"Grails, convert string to enum, enum, Groovy, transform string to enum\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/groovy-few-ways-to-convert-string-into-enum\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"position\":2,\"name\":\"Grails\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/groovy-few-ways-to-convert-string-into-enum\\\/#listItem\",\"name\":\"Groovy: Few ways to convert string into enum\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/groovy-few-ways-to-convert-string-into-enum\\\/#listItem\",\"position\":3,\"name\":\"Groovy: Few ways to convert string into enum\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/grails\\\/#listItem\",\"name\":\"Grails\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/amit\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/amit\\\/\",\"name\":\"Amit Jain\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/groovy-few-ways-to-convert-string-into-enum\\\/#authorImage\",\"url\":\"https:\\\/\\\/newersworld-sf-static.tothenew.net\\\/prod\\\/profilePicFolder\\\/1cbbcbd3-718c-4d6d-829c-4e225ae91a1a_amit.jain@tothenew.com.jpg\",\"width\":96,\"height\":96,\"caption\":\"Amit Jain\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/groovy-few-ways-to-convert-string-into-enum\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/groovy-few-ways-to-convert-string-into-enum\\\/\",\"name\":\"Groovy: Few ways to convert string into enum | TO THE NEW Blog\",\"description\":\"Many at times, we have a string which needs to be converted into Enum. I will be sharing few options as stated by Mr.Haki\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/groovy-few-ways-to-convert-string-into-enum\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/amit\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/amit\\\/#author\"},\"datePublished\":\"2011-04-15T00:48:30+05:30\",\"dateModified\":\"2022-01-12T19:33:57+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Groovy: Few ways to convert string into enum | TO THE NEW Blog","description":"Many at times, we have a string which needs to be converted into Enum. I will be sharing few options as stated by Mr.Haki","canonical_url":"https:\/\/tothenewco.pro\/blog\/groovy-few-ways-to-convert-string-into-enum\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/tothenewco.pro\/blog\/groovy-few-ways-to-convert-string-into-enum\/#article","name":"Groovy: Few ways to convert string into enum | TO THE NEW Blog","headline":"Groovy: Few ways to convert string into enum","author":{"@id":"https:\/\/tothenewco.pro\/blog\/author\/amit\/#author"},"publisher":{"@id":"https:\/\/tothenewco.pro\/blog\/#organization"},"datePublished":"2011-04-15T00:48:30+05:30","dateModified":"2022-01-12T19:33:57+05:30","inLanguage":"en-US","commentCount":2,"mainEntityOfPage":{"@id":"https:\/\/tothenewco.pro\/blog\/groovy-few-ways-to-convert-string-into-enum\/#webpage"},"isPartOf":{"@id":"https:\/\/tothenewco.pro\/blog\/groovy-few-ways-to-convert-string-into-enum\/#webpage"},"articleSection":"Grails, convert string to enum, enum, Groovy, transform string to enum"},{"@type":"BreadcrumbList","@id":"https:\/\/tothenewco.pro\/blog\/groovy-few-ways-to-convert-string-into-enum\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog#listItem","position":1,"name":"Home","item":"https:\/\/tothenewco.pro\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog\/category\/grails\/#listItem","name":"Grails"}},{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog\/category\/grails\/#listItem","position":2,"name":"Grails","item":"https:\/\/tothenewco.pro\/blog\/category\/grails\/","nextItem":{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog\/groovy-few-ways-to-convert-string-into-enum\/#listItem","name":"Groovy: Few ways to convert string into enum"},"previousItem":{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog\/groovy-few-ways-to-convert-string-into-enum\/#listItem","position":3,"name":"Groovy: Few ways to convert string into enum","previousItem":{"@type":"ListItem","@id":"https:\/\/tothenewco.pro\/blog\/category\/grails\/#listItem","name":"Grails"}}]},{"@type":"Organization","@id":"https:\/\/tothenewco.pro\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/tothenewco.pro\/blog\/"},{"@type":"Person","@id":"https:\/\/tothenewco.pro\/blog\/author\/amit\/#author","url":"https:\/\/tothenewco.pro\/blog\/author\/amit\/","name":"Amit Jain","image":{"@type":"ImageObject","@id":"https:\/\/tothenewco.pro\/blog\/groovy-few-ways-to-convert-string-into-enum\/#authorImage","url":"https:\/\/newersworld-sf-static.tothenew.net\/prod\/profilePicFolder\/1cbbcbd3-718c-4d6d-829c-4e225ae91a1a_amit.jain@tothenew.com.jpg","width":96,"height":96,"caption":"Amit Jain"}},{"@type":"WebPage","@id":"https:\/\/tothenewco.pro\/blog\/groovy-few-ways-to-convert-string-into-enum\/#webpage","url":"https:\/\/tothenewco.pro\/blog\/groovy-few-ways-to-convert-string-into-enum\/","name":"Groovy: Few ways to convert string into enum | TO THE NEW Blog","description":"Many at times, we have a string which needs to be converted into Enum. I will be sharing few options as stated by Mr.Haki","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/tothenewco.pro\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/tothenewco.pro\/blog\/groovy-few-ways-to-convert-string-into-enum\/#breadcrumblist"},"author":{"@id":"https:\/\/tothenewco.pro\/blog\/author\/amit\/#author"},"creator":{"@id":"https:\/\/tothenewco.pro\/blog\/author\/amit\/#author"},"datePublished":"2011-04-15T00:48:30+05:30","dateModified":"2022-01-12T19:33:57+05:30"},{"@type":"WebSite","@id":"https:\/\/tothenewco.pro\/blog\/#website","url":"https:\/\/tothenewco.pro\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/tothenewco.pro\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Groovy: Few ways to convert string into enum | TO THE NEW Blog","og:description":"Many at times, we have a string which needs to be converted into Enum. I will be sharing few options as stated by Mr.Haki","og:url":"https:\/\/tothenewco.pro\/blog\/groovy-few-ways-to-convert-string-into-enum\/","og:image":"https:\/\/tothenewco.pro\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/tothenewco.pro\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Groovy: Few ways to convert string into enum | TO THE NEW Blog","twitter:description":"Many at times, we have a string which needs to be converted into Enum. I will be sharing few options as stated by Mr.Haki","twitter:image":"https:\/\/tothenewco.pro\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"3673","title":null,"description":"Many at times, we have a string which needs to be converted into Enum. I will be sharing few options as stated by Mr.Haki","keywords":[],"keyphrases":{"focus":[],"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"blog","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"summary","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":{"id":"#aioseo-article-65e04ced966f8","slug":"article","graphName":"Article","label":"Article","properties":{"type":"BlogPosting","name":"#post_title","headline":"#post_title","description":"#post_excerpt","image":"","keywords":"","author":{"name":"#author_name","url":"#author_url"},"dates":{"include":true,"datePublished":"","dateModified":""}}},"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"}}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"limit_modified_date":false,"created":"2021-04-29 14:40:35","updated":"2024-02-29 09:22:53","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/tothenewco.pro\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/tothenewco.pro\/blog\/category\/grails\/\" title=\"Grails\">Grails<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tGroovy: Few ways to convert string into enum\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/tothenewco.pro\/blog"},{"label":"Grails","link":"https:\/\/tothenewco.pro\/blog\/category\/grails\/"},{"label":"Groovy: Few ways to convert string into enum","link":"https:\/\/tothenewco.pro\/blog\/groovy-few-ways-to-convert-string-into-enum\/"}],"_links":{"self":[{"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/posts\/3673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/comments?post=3673"}],"version-history":[{"count":2,"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/posts\/3673\/revisions"}],"predecessor-version":[{"id":54615,"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/posts\/3673\/revisions\/54615"}],"wp:attachment":[{"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/media?parent=3673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/categories?post=3673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tothenewco.pro\/blog\/wp-json\/wp\/v2\/tags?post=3673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}