[ 
https://issues.apache.org/jira/browse/FREEMARKER-67?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Pu Zhongqiang updated FREEMARKER-67:
------------------------------------
    Description: 
In mongodb's Java Driver 3.x, org.bson.Document is a representation of a bson 
document as a Map. Although org.bson.Document is not a subclass of 
LinkedHashMap, it really DOES maintain a meaningful order for its keys.

It works good if I use LinkedHashMap to load data.

{code:java}
LinkedHashMap<String,Object> accepted_sorts = new LinkedHashMap<>();
accepted_sorts.put("-favorite_time", "Hello");
accepted_sorts.put("-publish_time", "Welcome");
model.put("accepted_sorts", accepted_sorts);
{code}

{code:html}
<#list accepted_sorts?keys as value>
        ${value?string}
</#list>
<br>
<#list accepted_sorts as key,value>
        ${key?string},${value?string}
</#list>
{code}
it rendered as: 

{code:html}
-favorite_time -publish_time 
-favorite_time,Hello -publish_time,Welcome 
{code}


But Freemarker doesn't support  org.bson.Document's correct key order. You can 
see my test below:

{code:java}
Document accepted_sorts = new Document();
accepted_sorts.put("-favorite_time", "Hello");
accepted_sorts.put("-publish_time", "Welcome");
model.put("accepted_sorts", accepted_sorts);
{code}

{code:html}
<#list accepted_sorts?keys as value>
        ${value?string}
</#list>
<br>
<#list accepted_sorts as key,value>
        ${key?string},${value?string}
</#list>
{code}
it rendered as wrong order: 

{code:html}
-publish_time -favorite_time 
-publish_time,Welcome -favorite_time,Hello 
{code}

So, in the end, I wish freemarker can add support for org.bson.Document's 
correct order of keys.

  was:
In mongdb's Java Driver 3.x, org.bson.Document is a representation of a bson 
document as a Map. Although org.bson.Document is not a subclass of 
LinkedHashMap, it really DOES maintain a meaningful order for its keys.

It works good if I use LinkedHashMap to load data.

{code:java}
LinkedHashMap<String,Object> accepted_sorts = new LinkedHashMap<>();
accepted_sorts.put("-favorite_time", "Hello");
accepted_sorts.put("-publish_time", "Welcome");
model.put("accepted_sorts", accepted_sorts);
{code}

{code:html}
<#list accepted_sorts?keys as value>
        ${value?string}
</#list>
<br>
<#list accepted_sorts as key,value>
        ${key?string},${value?string}
</#list>
{code}
it rendered as: 

{code:html}
-favorite_time -publish_time 
-favorite_time,Hello -publish_time,Welcome 
{code}


But Freemarker doesn't support  org.bson.Document's correct key order. You can 
see my test below:

{code:java}
Document accepted_sorts = new Document();
accepted_sorts.put("-favorite_time", "Hello");
accepted_sorts.put("-publish_time", "Welcome");
model.put("accepted_sorts", accepted_sorts);
{code}

{code:html}
<#list accepted_sorts?keys as value>
        ${value?string}
</#list>
<br>
<#list accepted_sorts as key,value>
        ${key?string},${value?string}
</#list>
{code}
it rendered as wrong order: 

{code:html}
-publish_time -favorite_time 
-publish_time,Welcome -favorite_time,Hello 
{code}

So, in the end, I wish freemarker can add support for org.bson.Document's 
correct order of keys.


> Doesn't support org.bson.Document's correct order of keys.
> ----------------------------------------------------------
>
>                 Key: FREEMARKER-67
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-67
>             Project: Apache Freemarker
>          Issue Type: Bug
>          Components: engine
>    Affects Versions: 2.3.23, 2.3.24-incubating, 2.3.25-incubating, 
> 2.3.26-incubating
>         Environment: Windows7, jdk1.8.0_131, Tomcat 8.0.45, SpringMVC 
> 4.3.10.RELEASE
>            Reporter: Pu Zhongqiang
>            Priority: Minor
>              Labels: features
>
> In mongodb's Java Driver 3.x, org.bson.Document is a representation of a bson 
> document as a Map. Although org.bson.Document is not a subclass of 
> LinkedHashMap, it really DOES maintain a meaningful order for its keys.
> It works good if I use LinkedHashMap to load data.
> {code:java}
> LinkedHashMap<String,Object> accepted_sorts = new LinkedHashMap<>();
> accepted_sorts.put("-favorite_time", "Hello");
> accepted_sorts.put("-publish_time", "Welcome");
> model.put("accepted_sorts", accepted_sorts);
> {code}
> {code:html}
> <#list accepted_sorts?keys as value>
>       ${value?string}
> </#list>
> <br>
> <#list accepted_sorts as key,value>
>       ${key?string},${value?string}
> </#list>
> {code}
> it rendered as: 
> {code:html}
> -favorite_time -publish_time 
> -favorite_time,Hello -publish_time,Welcome 
> {code}
> But Freemarker doesn't support  org.bson.Document's correct key order. You 
> can see my test below:
> {code:java}
> Document accepted_sorts = new Document();
> accepted_sorts.put("-favorite_time", "Hello");
> accepted_sorts.put("-publish_time", "Welcome");
> model.put("accepted_sorts", accepted_sorts);
> {code}
> {code:html}
> <#list accepted_sorts?keys as value>
>       ${value?string}
> </#list>
> <br>
> <#list accepted_sorts as key,value>
>       ${key?string},${value?string}
> </#list>
> {code}
> it rendered as wrong order: 
> {code:html}
> -publish_time -favorite_time 
> -publish_time,Welcome -favorite_time,Hello 
> {code}
> So, in the end, I wish freemarker can add support for org.bson.Document's 
> correct order of keys.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to