Google Gson Interview Questions and Answers
Ques. How to provide Pretty Printing for JSON Output Format?Ans.
The default JSON output that is provide by Gson is a compact JSON format. This means that there will not be any white-space in the output JSON structure. To generate a more readable and pretty looking JSON use setPrettyPrinting() in GsonBuilder.
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String jsonOutput = gson.toJson(employee);
Is it helpful? Yes No
Most helpful rated by users: