<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>AnyWare</title>
	<link>http://www.anyware.co.uk/2005</link>
	<description>Development &#038; consultancy services</description>
	<pubDate>Tue, 22 Jul 2008 11:18:03 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1</generator>
	<language>en</language>
			<item>
		<title>A Grails JSON Builder that doesn&#8217;t suck</title>
		<link>http://www.anyware.co.uk/2005/2008/06/19/a-grails-json-builder-that-doesnt-suck/</link>
		<comments>http://www.anyware.co.uk/2005/2008/06/19/a-grails-json-builder-that-doesnt-suck/#comments</comments>
		<pubDate>Thu, 19 Jun 2008 19:21:55 +0000</pubDate>
		<dc:creator>Marc Palmer</dc:creator>
		
		<category><![CDATA[Groovy and Grails]]></category>

		<guid isPermaLink="false">http://www.anyware.co.uk/2005/2008/06/19/a-grails-json-builder-that-doesnt-suck/</guid>
		<description><![CDATA[Now we&#8217;ve been doing some fun Ajax bits with JSON recently in Grails. However it has been very painful using the JSON builder. Initially I didn&#8217;t want to use the JSON converter (render x as JSON) as the data is coming from several sources, and there are some domain class properties we don&#8217;t want to [...]]]></description>
			<content:encoded><![CDATA[<p>Now we&#8217;ve been doing some fun Ajax bits with JSON recently in Grails. However it has been very painful using the JSON builder. Initially I didn&#8217;t want to use the JSON converter (render x as JSON) as the data is coming from several sources, and there are some domain class properties we don&#8217;t want to expose.</p>
<p>So the builder approach seemed to make sense. The only trouble is that <strong>render(contentType:&#8217;text/json&#8217;) { &#8230; } </strong>uses Grails default JSONBuilder which I have discovered sucks, and also blows.</p>
<p>The default JSONBuilder uses method calls for everything. However in some cases the method name is ignored - eg elements of an array. Also you can only set name/value pairs with simple method(value) constructs on the root node of the builder, as in subnodes each one of these creates a new object eg { method: value }. The final blow for me was that property values of anything other than simple types are just rendered as strings. For example a property value that is an array of ints is rendered as a string so &quot;[1, 2, 3, 4]&quot; because <a href="http://jira.codehaus.org/browse/GRAILS-3147">JSONWriter has just a def value(Object) method that calls toString()</a>. This is in contrast to the &quot;as JSON&quot; converter construct which works nicely with nested objects and is sane when it comes to recursion/parent node references.</p>
<p>So as soon as you step away from trivial lists and have any kind of object graph to represent, it falls down.</p>
<p>Enough was enough so I knocked this together. It needs a lot more sanity checking in there and possibly some optimisation but it took half an hour and it works. Using it is a case of calling &quot;render new BetterJSONBuilder() { &#8230; }&quot;.</p>
<p>What it does is use any method calls with a Map to create a new JSON object with those properties. Any method call with a closure creates a new array OR object - if the first call in a closure is to &quot;element(value)&quot; it will create an array. Property access is permitted on object nodes eg you set properties with x=y not with x(y) as in the standard horrible JSONBuilder.</p>
<p>Internally it just creates a tree of maps/lists and then uses &quot;as JSON&quot; to do the conversion. Short and sweet.</p>
<div class="ch_code_container" style="font-family: monospace;height:200px;"><p><a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20class"><span style="color: #000000; font-weight: bold;">class</span></a> BetterJSONBuilder <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20static"><span style="color: #000000; font-weight: bold;">static</span></a> NODE_ELEMENT = <span style="color: #ff0000;">&quot;element&quot;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20def"><span style="color: #000000; font-weight: bold;">def</span></a> root<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20def"><span style="color: #000000; font-weight: bold;">def</span></a> current<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20def"><span style="color: #000000; font-weight: bold;">def</span></a> nestingStack = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20def"><span style="color: #000000; font-weight: bold;">def</span></a> build<span style="color: #66cc66;">&#40;</span>Closure c<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; c.<span style="color: #006600;">delegate</span> = <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20this"><span style="color: #000000; font-weight: bold;">this</span></a><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//c.resolveStrategy = Closure.DELEGATE_FIRST</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; root = <span style="color: #66cc66;">&#91;</span>:<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; current = root<br />
&nbsp; &nbsp; &nbsp; &nbsp; c.<a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20call"><span style="color: #993399; font-weight: bold;">call</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20return"><span style="color: #000000; font-weight: bold;">return</span></a> root <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20as"><span style="color: #000000; font-weight: bold;">as</span></a> JSON <span style="color: #808080; font-style: italic;">// requires deep</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20def"><span style="color: #000000; font-weight: bold;">def</span></a> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20invokeMethod"><span style="color: #993399;">invokeMethod</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.google.de/search?as_q=String&#038;num=100&#038;hl=en&#038;as_occt=url&#038;as_sitesearch=java.sun.com%2Fj2se%2F1.5.0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">String</span></a> methodName<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; current<span style="color: #66cc66;">&#91;</span>methodName<span style="color: #66cc66;">&#93;</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20def"><span style="color: #000000; font-weight: bold;">def</span></a> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20invokeMethod"><span style="color: #993399;">invokeMethod</span></a><span style="color: #66cc66;">&#40;</span><a href="http://www.google.de/search?as_q=String&#038;num=100&#038;hl=en&#038;as_occt=url&#038;as_sitesearch=java.sun.com%2Fj2se%2F1.5.0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">String</span></a> methodName, <a href="http://www.google.de/search?as_q=Object&#038;num=100&#038;hl=en&#038;as_occt=url&#038;as_sitesearch=java.sun.com%2Fj2se%2F1.5.0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">Object</span></a> args<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20if"><span style="color: #b1b100;">if</span></a> <span style="color: #66cc66;">&#40;</span>args.<a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20size"><span style="color: #663399;">size</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20if"><span style="color: #b1b100;">if</span></a> <span style="color: #66cc66;">&#40;</span>args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20instanceof"><span style="color: #000000; font-weight: bold;">instanceof</span></a> <a href="http://www.google.de/search?as_q=Map&#038;num=100&#038;hl=en&#038;as_occt=url&#038;as_sitesearch=java.sun.com%2Fj2se%2F1.5.0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">Map</span></a><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// switch root to an array if elements used at top level</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20if"><span style="color: #b1b100;">if</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>current == root<span style="color: #66cc66;">&#41;</span> &amp;&amp; <span style="color: #66cc66;">&#40;</span>methodName == NODE_ELEMENT<span style="color: #66cc66;">&#41;</span> &amp;&amp; !<span style="color: #66cc66;">&#40;</span>root <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20instanceof"><span style="color: #000000; font-weight: bold;">instanceof</span></a> <a href="http://www.google.de/search?as_q=List&#038;num=100&#038;hl=en&#038;as_occt=url&#038;as_sitesearch=java.sun.com%2Fj2se%2F1.5.0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">List</span></a><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20if"><span style="color: #b1b100;">if</span></a> <span style="color: #66cc66;">&#40;</span>root.<a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20size"><span style="color: #663399;">size</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20throw"><span style="color: #000000; font-weight: bold;">throw</span></a> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20new"><span style="color: #000000; font-weight: bold;">new</span></a> <a href="http://www.google.de/search?as_q=IllegalArgumentException&#038;num=100&#038;hl=en&#038;as_occt=url&#038;as_sitesearch=java.sun.com%2Fj2se%2F1.5.0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">IllegalArgumentException</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;Cannot have array elements in root node if properties of root have already been set&#8217;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20else"><span style="color: #b1b100;">else</span></a> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; root = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; current = root<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20def"><span style="color: #000000; font-weight: bold;">def</span></a> n = <span style="color: #66cc66;">&#91;</span>:<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20if"><span style="color: #b1b100;">if</span></a> <span style="color: #66cc66;">&#40;</span>current <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20instanceof"><span style="color: #000000; font-weight: bold;">instanceof</span></a> <a href="http://www.google.de/search?as_q=List&#038;num=100&#038;hl=en&#038;as_occt=url&#038;as_sitesearch=java.sun.com%2Fj2se%2F1.5.0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">List</span></a><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20if"><span style="color: #b1b100;">if</span></a> <span style="color: #66cc66;">&#40;</span>methodName != NODE_ELEMENT<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20throw"><span style="color: #000000; font-weight: bold;">throw</span></a> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20new"><span style="color: #000000; font-weight: bold;">new</span></a> <a href="http://www.google.de/search?as_q=IllegalArgumentException&#038;num=100&#038;hl=en&#038;as_occt=url&#038;as_sitesearch=java.sun.com%2Fj2se%2F1.5.0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">IllegalArgumentException</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;Array elements must be defined with the &quot;element&quot; method call eg: element(value)&#8217;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; current <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20&amp;lt;"><span style="color: #b1b100;">&lt;&lt;</span></a> n<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20else"><span style="color: #b1b100;">else</span></a> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; current<span style="color: #66cc66;">&#91;</span>methodName<span style="color: #66cc66;">&#93;</span> = n<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n.<span style="color: #006600;">putAll</span><span style="color: #66cc66;">&#40;</span>args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20else"><span style="color: #b1b100;">else</span></a> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20if"><span style="color: #b1b100;">if</span></a> <span style="color: #66cc66;">&#40;</span>args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#93;</span> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20instanceof"><span style="color: #000000; font-weight: bold;">instanceof</span></a> Closure<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20def"><span style="color: #000000; font-weight: bold;">def</span></a> n = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nestingStack <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20&amp;lt;"><span style="color: #b1b100;">&lt;&lt;</span></a> current</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20if"><span style="color: #b1b100;">if</span></a> <span style="color: #66cc66;">&#40;</span>current <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20instanceof"><span style="color: #000000; font-weight: bold;">instanceof</span></a> <a href="http://www.google.de/search?as_q=List&#038;num=100&#038;hl=en&#038;as_occt=url&#038;as_sitesearch=java.sun.com%2Fj2se%2F1.5.0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">List</span></a><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; current <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20&amp;lt;"><span style="color: #b1b100;">&lt;&lt;</span></a> n<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20else"><span style="color: #b1b100;">else</span></a> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; current<span style="color: #66cc66;">&#91;</span>methodName<span style="color: #66cc66;">&#93;</span> = n<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; current = n<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#93;</span>.<a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20call"><span style="color: #993399; font-weight: bold;">call</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; current = nestingStack.<a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20pop"><span style="color: #663399;">pop</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20else"><span style="color: #b1b100;">else</span></a> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20if"><span style="color: #b1b100;">if</span></a> <span style="color: #66cc66;">&#40;</span>ars.<a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20size"><span style="color: #663399;">size</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> == <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20if"><span style="color: #b1b100;">if</span></a> <span style="color: #66cc66;">&#40;</span>methodName != NODE_ELEMENT<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20throw"><span style="color: #000000; font-weight: bold;">throw</span></a> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20new"><span style="color: #000000; font-weight: bold;">new</span></a> <a href="http://www.google.de/search?as_q=IllegalArgumentException&#038;num=100&#038;hl=en&#038;as_occt=url&#038;as_sitesearch=java.sun.com%2Fj2se%2F1.5.0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">IllegalArgumentException</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;Array elements must be defined with the &quot;element&quot; method call eg: element(value)&#8217;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// switch root to an array if elements used at top level</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20if"><span style="color: #b1b100;">if</span></a> <span style="color: #66cc66;">&#40;</span>current == root<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20if"><span style="color: #b1b100;">if</span></a> <span style="color: #66cc66;">&#40;</span>root.<a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20size"><span style="color: #663399;">size</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20throw"><span style="color: #000000; font-weight: bold;">throw</span></a> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20new"><span style="color: #000000; font-weight: bold;">new</span></a> <a href="http://www.google.de/search?as_q=IllegalArgumentException&#038;num=100&#038;hl=en&#038;as_occt=url&#038;as_sitesearch=java.sun.com%2Fj2se%2F1.5.0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">IllegalArgumentException</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;Cannot have array elements in root node if properties of root have already been set&#8217;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20else"><span style="color: #b1b100;">else</span></a> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; root = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; current = root<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20if"><span style="color: #b1b100;">if</span></a> <span style="color: #66cc66;">&#40;</span>current <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20instanceof"><span style="color: #000000; font-weight: bold;">instanceof</span></a> <a href="http://www.google.de/search?as_q=List&#038;num=100&#038;hl=en&#038;as_occt=url&#038;as_sitesearch=java.sun.com%2Fj2se%2F1.5.0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">List</span></a><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; current <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20&amp;lt;"><span style="color: #b1b100;">&lt;&lt;</span></a> args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20else"><span style="color: #b1b100;">else</span></a> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20throw"><span style="color: #000000; font-weight: bold;">throw</span></a> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20new"><span style="color: #000000; font-weight: bold;">new</span></a> <a href="http://www.google.de/search?as_q=IllegalArgumentException&#038;num=100&#038;hl=en&#038;as_occt=url&#038;as_sitesearch=java.sun.com%2Fj2se%2F1.5.0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">IllegalArgumentException</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&#8216;Array elements can only be defined under &quot;array&quot; nodes&#8217;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20else"><span style="color: #b1b100;">else</span></a> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20throw"><span style="color: #000000; font-weight: bold;">throw</span></a> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20new"><span style="color: #000000; font-weight: bold;">new</span></a> <a href="http://www.google.de/search?as_q=IllegalArgumentException&#038;num=100&#038;hl=en&#038;as_occt=url&#038;as_sitesearch=java.sun.com%2Fj2se%2F1.5.0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">IllegalArgumentException</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;This builder does not support invocation of [$methodName] with arg list ${args.dump()}&quot;</span><span style="color: #66cc66;">&#41;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20else"><span style="color: #b1b100;">else</span></a> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; current<span style="color: #66cc66;">&#91;</span>methodName<span style="color: #66cc66;">&#93;</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></p>
<p>&nbsp; &nbsp; <br />
&nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20void"><span style="color: #993333;">void</span></a> setProperty<span style="color: #66cc66;">&#40;</span><a href="http://www.google.de/search?as_q=String&#038;num=100&#038;hl=en&#038;as_occt=url&#038;as_sitesearch=java.sun.com%2Fj2se%2F1.5.0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">String</span></a> propName, <a href="http://www.google.de/search?as_q=Object&#038;num=100&#038;hl=en&#038;as_occt=url&#038;as_sitesearch=java.sun.com%2Fj2se%2F1.5.0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">Object</span></a> value<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; current<span style="color: #66cc66;">&#91;</span>propName<span style="color: #66cc66;">&#93;</span> = value<br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <a href="http://www.google.de/search?q=site%3Adocs.codehaus.org/%20def"><span style="color: #000000; font-weight: bold;">def</span></a> getProperty<span style="color: #66cc66;">&#40;</span><a href="http://www.google.de/search?as_q=String&#038;num=100&#038;hl=en&#038;as_occt=url&#038;as_sitesearch=java.sun.com%2Fj2se%2F1.5.0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">String</span></a> propName<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; current<span style="color: #66cc66;">&#91;</span>propName<span style="color: #66cc66;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div>
<p><strong><em>Update:</em> </strong>I found this morning that I missed out the &quot;import grails.converters.JSON&quot; from this. I also discovered that for me at least, if I imported the deep.JSON converter, I was getting lots of &quot;Value out of sequence&quot; exceptions. Using the normal non-deep JSON converter all is fine and, weirdly, nested objects seem fine too - e.g. I have a top level JS object, a value within it that is an array of other objects, and those objects have an array property also. All rendering fine without deep JSON converter.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anyware.co.uk/2005/2008/06/19/a-grails-json-builder-that-doesnt-suck/feed/</wfw:commentRss>
		</item>
		<item>
		<title>We need you - vacant job positions</title>
		<link>http://www.anyware.co.uk/2005/2008/06/16/we-need-you-vacant-job-positions/</link>
		<comments>http://www.anyware.co.uk/2005/2008/06/16/we-need-you-vacant-job-positions/#comments</comments>
		<pubDate>Mon, 16 Jun 2008 13:54:15 +0000</pubDate>
		<dc:creator>Marc Palmer</dc:creator>
		
		<category><![CDATA[Groovy and Grails]]></category>

		<guid isPermaLink="false">http://www.anyware.co.uk/2005/2008/06/16/we-need-you-vacant-job-positions/</guid>
		<description><![CDATA[Due to continued expansion, Enotions with whom I work extensively have several positions that need filling almost immediately.

Account manager - web savvy, very personable and professional you will be required to make frequent client meetings with several leading UK brands, to keep them informed about site progress, liaise on new developments and communicate client needs [...]]]></description>
			<content:encoded><![CDATA[<p>Due to continued expansion, <a href="http://www.enotions.co.uk">Enotions</a> with whom I work extensively have several positions that need filling almost immediately.</p>
<ul>
<li>Account manager - web savvy, very personable and professional you will be required to make frequent client meetings with several leading UK brands, to keep them informed about site progress, liaise on new developments and communicate client needs to our project managers.</li>
<li>QA / Tester - AKA Quality Nazi. We need someone who takes offence at not finding a bug in the site that we later find ourselves - or worse the client finds. Every site HAS to validate.&nbsp; Every site HAS to be link checked. Every client requirement HAS to be met. We don&#8217;t want ANY typos on live sites. Detailed issue tracking and moving towards automated testing should be things that get you excited. Our development teams are eager for you to kick their asses.</li>
<li>PHP and Javascript developer - we have an opening for a professional PHP and JS coder who will drive progress and quality in our small/mid-range customer sites introducing reliable and proven PHP database libraries and utilizing JS and Ajax, working with our HTML/CSS builders to produce polished sites</li>
</ul>
<p>If you fancy working from home, using skype as a lifeline, and want to help take this thriving business to the next level, please get in touch with Rob Richardson (workwithus@enotions.co.uk)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anyware.co.uk/2005/2008/06/16/we-need-you-vacant-job-positions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The smallest things bring great joy</title>
		<link>http://www.anyware.co.uk/2005/2008/06/09/the-smallest-things-bring-great-joy/</link>
		<comments>http://www.anyware.co.uk/2005/2008/06/09/the-smallest-things-bring-great-joy/#comments</comments>
		<pubDate>Mon, 09 Jun 2008 16:51:35 +0000</pubDate>
		<dc:creator>Marc Palmer</dc:creator>
		
		<category><![CDATA[Groovy and Grails]]></category>

		<guid isPermaLink="false">http://www.anyware.co.uk/2005/2008/06/09/the-smallest-things-bring-great-joy/</guid>
		<description><![CDATA[I just discovered to my joy that the recently released Grails 1.0.3 has a small but WONDERFUL feature added.
Line numbers are now shown in source code when you append ?showSource to your URL in development mode. This is extremely handy for debugging GSPs.
Thank you Graeme, or whoever implemented it.
&#160;
&#160;
&#160;
]]></description>
			<content:encoded><![CDATA[<p>I just discovered to my joy that the recently released Grails 1.0.3 has a small but WONDERFUL feature added.</p>
<p>Line numbers are now shown in source code when you append ?showSource to your URL in development mode. This is extremely handy for debugging GSPs.</p>
<p>Thank you Graeme, or whoever implemented it.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anyware.co.uk/2005/2008/06/09/the-smallest-things-bring-great-joy/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Grails Feeds Plugin 1.4 released</title>
		<link>http://www.anyware.co.uk/2005/2008/06/09/grails-feeds-plugin-14-released/</link>
		<comments>http://www.anyware.co.uk/2005/2008/06/09/grails-feeds-plugin-14-released/#comments</comments>
		<pubDate>Mon, 09 Jun 2008 15:12:43 +0000</pubDate>
		<dc:creator>Marc Palmer</dc:creator>
		
		<category><![CDATA[Groovy and Grails]]></category>

		<guid isPermaLink="false">http://www.anyware.co.uk/2005/2008/06/09/grails-feeds-plugin-14-released/</guid>
		<description><![CDATA[Today I released version 1.4 (we skipped 1.3) of the Grails feeds plugin for producing RSS and Atom feeds trivially from Grails applications.
This version fixes several annoying bugs that results in seemingly irrelevant error messages, and adds support for RSS enclosures, as well as iTunes music store specific podcast tags.
This version is in production serving [...]]]></description>
			<content:encoded><![CDATA[<p>Today I released version 1.4 (we skipped 1.3) of the Grails feeds plugin for producing RSS and Atom feeds trivially from Grails applications.</p>
<p>This version fixes several annoying bugs that results in seemingly irrelevant error messages, and adds support for RSS enclosures, as well as iTunes music store specific podcast tags.</p>
<p>This version is in production serving up a podcast in the iTunes Music Store.</p>
<p>To install type: grails install-plugin grails-feeds</p>
<p>Documentation updated to include enclosures and iTunes tags is <a href="http://grails.org/Feeds+Plugin">here</a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anyware.co.uk/2005/2008/06/09/grails-feeds-plugin-14-released/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Prototype Library for Javascript - versioning brainiacs?</title>
		<link>http://www.anyware.co.uk/2005/2008/05/19/prototype-library-for-javascript-versioning-brainiacs/</link>
		<comments>http://www.anyware.co.uk/2005/2008/05/19/prototype-library-for-javascript-versioning-brainiacs/#comments</comments>
		<pubDate>Mon, 19 May 2008 10:21:28 +0000</pubDate>
		<dc:creator>Marc Palmer</dc:creator>
		
		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Groovy and Grails]]></category>

		<guid isPermaLink="false">http://www.anyware.co.uk/2005/2008/05/19/prototype-library-for-javascript-versioning-brainiacs/</guid>
		<description><![CDATA[Hmm oh dear.
I&#8217;m working on some trivial Javascript code for a new site to add a little dynamic behaviour, using the &#34;trusty&#34; Prototype JS library that we have loved before. Only, property/array access on Hash objects is not working any more. I waste a lot of time on this.
Then I find this blog post on [...]]]></description>
			<content:encoded><![CDATA[<p>Hmm oh dear.</p>
<p>I&#8217;m working on some trivial Javascript code for a new site to add a little dynamic behaviour, using the &quot;trusty&quot; Prototype JS library that we have loved before. Only, property/array access on Hash objects is not working any more. I waste a lot of time on this.</p>
<p>Then I find <a href="http://www.prototypejs.org/2007/10/16/prototype-1-6-0-rc1-changes-to-the-class-and-event-apis-hash-rewrite-and-bug-fixes">this blog post on the prototype website</a>.</p>
<p>Yes that&#8217;s right, in version 1.6 they made a completely breaking change to the behaviour of Hash - array indexing is no longer possible, you must call Hash.get(key). This makes me rather worried as it seems the developers are not aware of the concept of minor revisions not changing the public interface of a library.</p>
<p>Bizarre. I can only wonder what other functionality will be broken in other pre-2.0 releases. This has shaken my confidence in Prototype I must say.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.anyware.co.uk/2005/2008/05/19/prototype-library-for-javascript-versioning-brainiacs/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
