Read & write file using Gson streaming

You could read & write file using Gson streaming. It is a powerful feature of Gson. Gson Streaming API is based on sequential read & write standard. And JsonWriter & JsonReader are core classes built for Streaming Write and Read in Streaming API. I show you how to use JsonWriter and JsonReader via two programs … Read more

Parse json string and java object into Gson tree model

GSON Tree Model API provides JsonParser help you parse Json string to tree model of JsonElement. Beside, JsonElement provides method isJsonXXX() and getAsYYY() to check type of Json element and get value of element on that tree node. On the writing, Gson Tree Model API provides method toJsonTree help you converts a java object into … Read more

Convert Java collections into JSON and JSON to collections

This sample show you how to convert Java collections into JSON string. A collections of fruit is built and converted to json object. Then whereas json object is convert to collections object

This is output of program jsonFruitNames = [“Banana”,”Apple”,”Orange”,”Kiwi”] jsonFruits = [{“name”:”Banana”,”location”:”Cuba”,”recommend”:”Should buy”},{“name”:”Apple”,”location”:”USA”,”recommend”:”Should eat”},{“name”:”Orange”,”location”:”Holland”,”recommend”:””},{“name”:”Kiwi”,”location”:”Sweeden”,”recommend”:””}] fruit.getName() = Banana fruit.getLocation() = Cuba fruit.getRecommend() = Should … Read more

Please share it if you found this useful
Hide Buttons