title: Groovy JsonBuilder: object properties being serialized in random order
body: <p>I'm currently having a problem with the groovy JsonBuilder: the properties of the objects I am trying to serialize are coming out in seemingly random order.</p>
  
  <p>Here's the objects' class:</p>
  
  <pre><code>class Game {
      String title
      String gameImg2
      String description
  }
  </code></pre>
  
  <p>And this is the code I've been using:</p>
  
  <pre><code>def game = new Game(title: "a game", gameImg2: "an image", description: "desc")
  def json = new JsonBuilder(game)
  </code></pre>
  
  <p>From this I would expect the output to be: </p>
  
  <pre><code>{"title":"a game","gameImg2":"an image", "description":"desc"}
  </code></pre>
  
  <p>but instead, I'm getting: </p>
  
  <pre><code>{"gameImg2":"gameImg","title":"hello","description":"desc"}.
  </code></pre>
  
  <p>From looking at the <a href="http://groovy.codehaus.org/gapi/groovy/json/JsonBuilder.html" rel="nofollow">JsonBuilder example code</a>, it seems that order should be maintained, and indeed, it looks like the toJson method iterates over object.properties, which is a LinkedHashMap. I would have thought this would go through the properties in the order they are declared in the class.</p>
  
  <p>My best guess is that this is something to do with my initialisation of the game object - could using Map syntax to assign properties somehow, but again, this seems to create a LinkedHashMap which should preserve order.</p>
  
  <p>Does anyone have an inkling of what I could have done wrong or incorrectly assumed here? Any leads would be a big help!</p>