Spring 4 Jackson Hashmap to Json losing ordering of keys
<p>I am using Spring 4 and Jackson. I am trying to return a LinkedHashMap from controller to Ajax Response.
However when Jackson is converting it to JSON the order of keys in the LinkedHashMap is getting lost.
How can I maintain the order of records.</p>

<p>Controller code:</p>

<pre><code>@ResponseBody
@RequestMapping(value = "/getLevel2", method = RequestMethod.POST)
public  LinkedHashMap&lt;String, String&gt; getLevel2(HttpServletRequest request)
{
        System.out.println("In getLevel2"+request.getParameterNames());

        String catId=request.getParameter("catId");
        String fkey=request.getParameter("key");
        LinkedHashMap&lt;String, String&gt; h=categoryService.getCategoryLevel2Map(2100,fkey);
        System.out.println(h);
        return h;
}
</code></pre>

<p>Ajax call:</p>

<pre><code>var jqxhr = $.ajax({
            type: "POST",
            url:"/a2bNext/getLevel2",
            cache: false,   
            data:'catId='+ catId+'&amp;key='+selectedValue 

            } )
            .done(function(data) {

                $("#level2").empty();
                for (var key in data) {
                    value=data[key];
                    isLeaf=value.split('::')[1];
                    value=value.split('::')[0];

                    if(isLeaf==1)
                    {
                        option = $('&lt;option&gt;&lt;/option&gt;').attr("value", key).text(value);
                        $("#level2").append(option);
                    }
                    else
                    {
                        option = $('&lt;option&gt;&lt;/option&gt;').attr("value", key).attr("class","subdivide").text(value);
                        $("#level2").append(option);
                    }

                }
                $("#level2").show();

            })
            .fail(function() {
                alert( "error1" );
            })
            .always(function() {
                //alert( "complete" );
            });

        });
</code></pre>

<p>Could anyone suggest how can I get the keys in ajax response in the same order as in LinkedHashMap.</p>