title: Serialized JSON with sorted keys, using Jackson
body: <p>I'm trying to replace a custom JSON (de)serialization in a groovy/grails project with Jackson.</p>
  
  <p>I'm having trouble getting Jackson to output a pretty-printed JSON with keys sorted in a simple 'natural' alphabetic order.
  I've tried this (and many variations):</p>
  
  <pre><code>mymap = [ ... ] // Some groovy map
  def mapper = new ObjectMapper()
  mapper.configure(SerializationConfig.Feature.SORT_PROPERTIES_ALPHABETICALLY, true)
  def jsonstring = mapper.defaultPrettyPrintingWriter().writeValueAsString(mymap)
  </code></pre>
  
  <p>But Jackson stubbornly generates a JSON where the keys seem to be in a random order.
  I've tried changing the type of 'mymap' with a TreeMap, and in that case all keys are properly sorted as expected.</p>
  
  <p>I'm wondering if there is a way to get the keys sorted <strong>without</strong> changing 'mymap' above to a TreeMap (and recursively all of its map values...).</p>
  
  <p>SORT_PROPERTIES_ALPHABETICALLY seems to be intended to do precisely that, but it's not doing it for some reason.
  Would you know why that is? Anything I'm doing wrong above?</p>
  
  <p>I've tried with Jackson 1.8.3, 1.8.8 and 1.9.5, same result (random keys).</p>