Without Book Interview Questions and Answers | Online Test | Moct Test
Download Android App in your Android Device from Google Play Store
- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
Institute Training Search by Name or Email

Exams Attended

Make Homepage

Bookmark this page

Subscribe Email Address

Google Gson Interview Questions and Answers

Ques. How to convert Java objects to JSON format?
Ans.
To convert the java objects to JSON format, use toJson() method.

Employee employee = new Employee();
employee.setId(1);
employee.setFirstName("Arindam");
employee.setLastName("Ghosh");
employee.setRoles(Arrays.asList("FINANCE", "MANAGER"));

Gson gson = new Gson();
System.out.println(gson.toJson(employee));

Output:
{"id":1,"firstName":"Arindam","lastName":"Ghosh","roles":["FIINANCE","MANAGER"]}
Is it helpful? Yes No

Most helpful rated by users:

©2016 WithoutBook