How to Convert Map to JSON in Java using Gson API

Convert Map to JSON in Java

Simple example about, How to Convert Map to JSON in Java using Gson API.

Item.java

MapConversion.java

Output

{“102”:{“itemId”:101,”itemName”:”C”,”itemDesc”:”C Language”},”103″:{“itemId”:101,”itemName”:”Python”,”itemDesc”:”Python Language”},”101″:{“itemId”:101,”itemName”:”Java”,”itemDesc”:”Java Language”},”104″:{“itemId”:101,”itemName”:”Ruby”,”itemDesc”:”Ruby Language”},”105″:{“itemId”:101,”itemName”:”Php”,”itemDesc”:”PHP Language”}}

References

1. Gson API JavaDocs