{"id":1441,"date":"2010-08-11T12:15:29","date_gmt":"2010-08-11T06:45:29","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=1441"},"modified":"2010-08-11T12:16:10","modified_gmt":"2010-08-11T06:46:10","slug":"using-binddata-in-services","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/using-binddata-in-services\/","title":{"rendered":"Using bindData in services"},"content":{"rendered":"<p>In one of my projects, I was working on rest calls, and one of the requirement was such that I had to pass the XML to service and then parse it and bind the relevant details to an instance of a domain object. In essence I had to call bindData in service after creating a Map from the XML. I soon realised we could not call bindData in service, its a method injected by grails only in controllers. After searching for stuff on google.. I found the way out, it was simple All we have to do is<\/p>\n<pre lang=\"groovy\"> \r\nimport org.codehaus.groovy.grails.web.metaclass.BindDynamicMethod\r\n<\/pre>\n<p>and then in your method do<\/p>\n<pre lang=\"groovy\"> \r\nBindDynamicMethod bind = new BindDynamicMethod()\r\nargs =  [objectInstance, map, [exclude:['prop1', 'prop2']]]\r\n        bind.invoke(objectInstance,'bind',(Object[]) args)\r\n<\/pre>\n<p>Here is the Link which I referred <a href=\"http:\/\/jts-blog.com\/?p=215\">JT&#8217;s Blog<\/a> it will give you a little more detail regarding using bindData in services.<\/p>\n<p>Hope it helps.<\/p>\n<p>With Regards<br \/>\nSachin Anand<br \/>\nsachin@intelligrape.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In one of my projects, I was working on rest calls, and one of the requirement was such that I had to pass the XML to service and then parse it and bind the relevant details to an instance of a domain object. In essence I had to call bindData in service after creating a [&hellip;]<\/p>\n","protected":false},"author":14,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0},"categories":[7],"tags":[361,229],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/1441"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=1441"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/1441\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=1441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=1441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=1441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}