Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Google%20Gson%20Interview%20Questions%20and%20Answers

Question: How to convert JSON to Java Objects?
Answer:
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:

©2024 WithoutBook