Hi Sohani,

+1 to use LinkedHashMaps instead of HashMaps since former make sure the
order of the items as you have mentioned. LinkedHashMaps has a higher
memory footprint but it has a better performance when accessing values in
the map (refer [1]). If we need a guarantee in the order of items we insert
into the map, there is no option than using the LinkedHashMap.

[1]
http://stackoverflow.com/questions/12998568/hashmap-vs-linkedhashmap-performance-in-iteration-over-values

Thanks,
Chanaka

On Mon, Jun 20, 2016 at 2:51 PM, Sohani Weerasinghe <soh...@wso2.com> wrote:

> Hi All,
>
> We are in a process of $subject and the main issue we faced in generating
> the json schema was as follows.
>
> When generating the json schema we mainly convert the xml to json and the
> xml to json conversion does not guarantee the order since json object is an
> unordered set of name/value pairs [1].
>
> The main reason is the usage of HashMaps instead of LinkedHashMaps in
> instantiating the JSONObjects and we could solve the issue by using the
> LinkedHashMaps.
>
> This issue again occurs in serializing the schema while iterating through
> the gmf tree, since we are generating the schema by creating the
> JSONObjects and JSONArrays appropriately. We could solve this issue as well
> by using the above solution and as a result, the generated tree and the
> schema will maintain the order of the XML payload
>
> [1]
> http://stackoverflow.com/questions/26034370/inverted-order-of-json-elements-in-java-after-xml-conversion
>
> Thanks,
> Sohani
> Sohani Weerasinghe
> Senior Software Engineer
> WSO2, Inc: http://wso2.com
>
> Mobile  : +94 716439774
> Blog     :http://christinetechtips.blogspot.com/
> Twitter  : https://twitter.com/sohanichristine
>



-- 
Thank you and Best Regards,
Chanaka Fernando
Senior Technical Lead
WSO2, Inc.; http://wso2.com
lean.enterprise.middleware

mobile: +94 773337238
Blog : http://soatutorials.blogspot.com
LinkedIn:http://www.linkedin.com/pub/chanaka-fernando/19/a20/5b0
Twitter:https://twitter.com/chanakaudaya
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to