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:
- What is Google-Gson?
- How to convert Java objects to JSON format?
- What are the two ways to create Gson objects?
- What is Instance Creator? Why and when do we require this?
- How to custom Serialization and De-serialization in Gson?