<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: XML to POJO via Groovy</title>
	<atom:link href="http://www.joergm.com/2009/03/xml-to-pojo-via-groovy/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.joergm.com/2009/03/xml-to-pojo-via-groovy/</link>
	<description>Agile software development and more by Joerg Mueller</description>
	<lastBuildDate>Wed, 25 Jan 2012 17:04:28 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
	<item>
		<title>By: Joerg</title>
		<link>http://www.joergm.com/2009/03/xml-to-pojo-via-groovy/comment-page-1/#comment-24</link>
		<dc:creator>Joerg</dc:creator>
		<pubDate>Tue, 31 Mar 2009 22:28:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.brainoutprintln.com/?p=54#comment-24</guid>
		<description>Hi Guillaume,

Damned. You found it. I thought I can trick everybody :)
In fact I did try the approach with yearlyIncome / 12. Unfortunatly this resulted in a BigDecimal of a different scale, which means they are not equal and my test failed. When using .divide(12) the scale was correct. So I did it this way and hoped that nobody would find out.

Do you have any idea why .divide(12) and /12 behave differently?</description>
		<content:encoded><![CDATA[<p>Hi Guillaume,</p>
<p>Damned. You found it. I thought I can trick everybody <img src='http://www.joergm.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
In fact I did try the approach with yearlyIncome / 12. Unfortunatly this resulted in a BigDecimal of a different scale, which means they are not equal and my test failed. When using .divide(12) the scale was correct. So I did it this way and hoped that nobody would find out.</p>
<p>Do you have any idea why .divide(12) and /12 behave differently?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Guillaume Laforge</title>
		<link>http://www.joergm.com/2009/03/xml-to-pojo-via-groovy/comment-page-1/#comment-23</link>
		<dc:creator>Guillaume Laforge</dc:creator>
		<pubDate>Mon, 30 Mar 2009 13:36:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.brainoutprintln.com/?p=54#comment-23</guid>
		<description>By the way, a very minor comment, you could do yearlyIncome / 12 instead of divide(12) :-)</description>
		<content:encoded><![CDATA[<p>By the way, a very minor comment, you could do yearlyIncome / 12 instead of divide(12) <img src='http://www.joergm.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joerg</title>
		<link>http://www.joergm.com/2009/03/xml-to-pojo-via-groovy/comment-page-1/#comment-13</link>
		<dc:creator>Joerg</dc:creator>
		<pubDate>Wed, 11 Mar 2009 07:24:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.brainoutprintln.com/?p=54#comment-13</guid>
		<description>@Rayk

To move the address code to another method I would simply refactor it like (Pseudocode follows)

---------------------------------------------------
Person transform(File)
{
 def xmlData = new XmlSlurper().parse(xml)  // only done once

//do the person stuff

Address address = doAdressStuff(xmlData)
person.address = address
// do the rest of the person stuff
return person
}

Address doAddressStuff(xmlData)
{
   //do the address stuff like in source example
  return address
}
---------------------------------------------------

In that example Address is part of the object tree, that needs to be returned. If the transformation ends in more than one root object, we could let transform return a Map instead of the root object. 

The parse call to the slurper happens only once in any case.</description>
		<content:encoded><![CDATA[<p>@Rayk</p>
<p>To move the address code to another method I would simply refactor it like (Pseudocode follows)</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
Person transform(File)<br />
{<br />
 def xmlData = new XmlSlurper().parse(xml)  // only done once</p>
<p>//do the person stuff</p>
<p>Address address = doAdressStuff(xmlData)<br />
person.address = address<br />
// do the rest of the person stuff<br />
return person<br />
}</p>
<p>Address doAddressStuff(xmlData)<br />
{<br />
   //do the address stuff like in source example<br />
  return address<br />
}<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</p>
<p>In that example Address is part of the object tree, that needs to be returned. If the transformation ends in more than one root object, we could let transform return a Map instead of the root object. </p>
<p>The parse call to the slurper happens only once in any case.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rayk</title>
		<link>http://www.joergm.com/2009/03/xml-to-pojo-via-groovy/comment-page-1/#comment-12</link>
		<dc:creator>Rayk</dc:creator>
		<pubDate>Tue, 10 Mar 2009 20:16:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.brainoutprintln.com/?p=54#comment-12</guid>
		<description>@Jörg: That it&#039;s slim for demo purposes, right. But what is the implication if you do it properly? Have a file-open wraper around every object transformation method? I&#039;m off programming, but could you let me know a smart and simple solution to that without producing masses of code?</description>
		<content:encoded><![CDATA[<p>@Jörg: That it&#8217;s slim for demo purposes, right. But what is the implication if you do it properly? Have a file-open wraper around every object transformation method? I&#8217;m off programming, but could you let me know a smart and simple solution to that without producing masses of code?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joerg</title>
		<link>http://www.joergm.com/2009/03/xml-to-pojo-via-groovy/comment-page-1/#comment-11</link>
		<dc:creator>Joerg</dc:creator>
		<pubDate>Tue, 10 Mar 2009 07:20:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.brainoutprintln.com/?p=54#comment-11</guid>
		<description>@Rayk,

Yes, I would split the whole method too. I just did not do it for demo purposes. If you want to pass the xml, just pass the xmlData Object. This is just a pointer to the slurper and passing it will not cause any re-read. 

The memory issue is interessting. I will have to try it.</description>
		<content:encoded><![CDATA[<p>@Rayk,</p>
<p>Yes, I would split the whole method too. I just did not do it for demo purposes. If you want to pass the xml, just pass the xmlData Object. This is just a pointer to the slurper and passing it will not cause any re-read. </p>
<p>The memory issue is interessting. I will have to try it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rayk</title>
		<link>http://www.joergm.com/2009/03/xml-to-pojo-via-groovy/comment-page-1/#comment-9</link>
		<dc:creator>Rayk</dc:creator>
		<pubDate>Mon, 09 Mar 2009 08:11:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.brainoutprintln.com/?p=54#comment-9</guid>
		<description>Me again, now on topic: It&#039;s a pitty that I need to work with ABAP, nothing like this available, nor possible. XML transformation is done in old school ways, but on single object level. So if there is any nesting we need to resolve it on our own. What happend before is that some black box converts a XML message into a deep structure, which we convert into rows for tables. No objects there.

I have a litte problem with the sketched solution. From modeling perspective I would create a second tranform method which creates adress objects, so I could maybe create alternate delivery adresses for orders etc. But how to pass the file content to avoid re-reading of the whole stuff? Another method to encapsulate file opening from file processing? I follow strug that one could run into memory issues here. 

Regards
Rayk

PS: I really L O V E the free yWorks editor</description>
		<content:encoded><![CDATA[<p>Me again, now on topic: It&#8217;s a pitty that I need to work with ABAP, nothing like this available, nor possible. XML transformation is done in old school ways, but on single object level. So if there is any nesting we need to resolve it on our own. What happend before is that some black box converts a XML message into a deep structure, which we convert into rows for tables. No objects there.</p>
<p>I have a litte problem with the sketched solution. From modeling perspective I would create a second tranform method which creates adress objects, so I could maybe create alternate delivery adresses for orders etc. But how to pass the file content to avoid re-reading of the whole stuff? Another method to encapsulate file opening from file processing? I follow strug that one could run into memory issues here. </p>
<p>Regards<br />
Rayk</p>
<p>PS: I really L O V E the free yWorks editor</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joerg</title>
		<link>http://www.joergm.com/2009/03/xml-to-pojo-via-groovy/comment-page-1/#comment-8</link>
		<dc:creator>Joerg</dc:creator>
		<pubDate>Sun, 08 Mar 2009 23:42:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.brainoutprintln.com/?p=54#comment-8</guid>
		<description>@Rayk
Yes, Wordpress behaves different than delicious. I just had to learn it :)

@strug
The mechanism for export is the XML builder. Pretty elegant too, but may be another article. 

As for the memory consumption, I have not tried it myself, but XmlSlurper is supposed to be more memory efficient than normal XML parsers. It uses some lazy initialization and reads only stuff that is asked for by the GPATH expressions.</description>
		<content:encoded><![CDATA[<p>@Rayk<br />
Yes, WordPress behaves different than delicious. I just had to learn it <img src='http://www.joergm.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>@strug<br />
The mechanism for export is the XML builder. Pretty elegant too, but may be another article. </p>
<p>As for the memory consumption, I have not tried it myself, but XmlSlurper is supposed to be more memory efficient than normal XML parsers. It uses some lazy initialization and reads only stuff that is asked for by the GPATH expressions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: strug</title>
		<link>http://www.joergm.com/2009/03/xml-to-pojo-via-groovy/comment-page-1/#comment-7</link>
		<dc:creator>strug</dc:creator>
		<pubDate>Sun, 08 Mar 2009 21:39:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.brainoutprintln.com/?p=54#comment-7</guid>
		<description>hi jörg, 
nice to see that you use 2 space indent as well :) sorry, off topic.
 
do you know if there is s.th. similar to export our objects into xml?

do you know if this solution works with very large documents as well? it looks like the xml is loaded into memory as a whole. 

one alternative we currently use, using a xsd and generate the java files with jaxb. next, the xml is automatically mapped into these interface objects. next, you need to map from interface object to domain object.</description>
		<content:encoded><![CDATA[<p>hi jörg,<br />
nice to see that you use 2 space indent as well <img src='http://www.joergm.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  sorry, off topic.</p>
<p>do you know if there is s.th. similar to export our objects into xml?</p>
<p>do you know if this solution works with very large documents as well? it looks like the xml is loaded into memory as a whole. </p>
<p>one alternative we currently use, using a xsd and generate the java files with jaxb. next, the xml is automatically mapped into these interface objects. next, you need to map from interface object to domain object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rayk</title>
		<link>http://www.joergm.com/2009/03/xml-to-pojo-via-groovy/comment-page-1/#comment-6</link>
		<dc:creator>Rayk</dc:creator>
		<pubDate>Sun, 08 Mar 2009 19:25:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.brainoutprintln.com/?p=54#comment-6</guid>
		<description>Off topic, but: It&#039;s great you re-aranged your tags, seems helpful for the usability of this site. POJO baby, behave!</description>
		<content:encoded><![CDATA[<p>Off topic, but: It&#8217;s great you re-aranged your tags, seems helpful for the usability of this site. POJO baby, behave!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

