Exams Attended

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Google Gson Interview Questions and Answers

Ques. How to convert JSON to Java Objects?
Ans.
To convert the JSON to java object, use fromJson() method.

Gson gson = new Gson();
System.out.println(
    gson.fromJson("{'id':1,'firstName':'Arindam','lastName':'Ghosh','roles':['FINANCE','MANAGER']}", 
    Employee.class));
     
Output:
Employee [id=1, firstName=Arindam, lastName=Ghosh, roles=[FINANCE, MANAGER]]

Is it helpful? Yes No

Most helpful rated by users:

©2021 WithoutBook