Answered step by step
Verified Expert Solution
Question
1 Approved Answer
JAVA The application uses gson-2.8.6.jar (or later), and must include that jar file in the zip file you submit to Canvas The application has at
JAVA
- The application uses gson-2.8.6.jar (or later), and must include that jar file in the zip file you submit to Canvas
- The application has at least the following four source-code files: StudentInfoGsonApp.java, Student.java, StudentList.java, PhoneNumber.java
- The main method in StudentInfoGsonApp does the following:
- creates the studentInfo String array as follows:
String[] studentInfo = {"John, Doe, 3.1, 800-555-1212, Solidity", "Jane, Deere, 3.25, 898-555-1212, swimming;sleeping;dreaming;kayaking;", "Sam, Spade, 2.9, 888-555-1212, coffee-drinking;Java;Python"};
- creates a new StudentList object and populates that StudentList object with three Student objects that take their values from studentInfo array above. Make sure that the phoneNumber in a Student object is a reference to a PhoneNumber object, not just a String, and that that skills variable in a Student is an array of Strings (the skills)).
- creates a new Gson object (ready for pretty printing) and uses a method of that object to convert your StudentList object to a JSON String.
- converts that JSON String back to a *new* StudentList object
- creates a new JsonObject called "jane" and adds all of the information in for Student Jane Deere to that JsonObject
- prints the output below by: 1) pretty-printing the first JSON String created above; 2) iterating through the new StudentList object you created to print its values; and 3) printing the values for Student Jane Deere
{ "students": [ { "firstName": "John", "lastName": "Doe", "gpa": 3.1, "phoneNumber": { "areaCode": 800, "prefix": 555, "lineNum": 1212 }, "skills": [ "Solidity" ] }, { "firstName": "Jane", "lastName": "Deere", "gpa": 3.25, "phoneNumber": { "areaCode": 898, "prefix": 555, "lineNum": 1212 }, "skills": [ "swimming", "sleeping", "dreaming", "kayaking" ] }, { "firstName": "Sam", "lastName": "Spade", "gpa": 2.9, "phoneNumber": { "areaCode": 888, "prefix": 555, "lineNum": 1212 }, "skills": [ "coffee-drinking", "Java", "Python" ] } ] } [firstName: John, lastName: Doe, gpa: 3.1, phoneNumber=800-555-1212, skills: [Solidity]] [firstName: Jane, lastName: Deere, gpa: 3.25, phoneNumber=898-555-1212, skills: [swimming,sleeping,dreaming,kayaking]] [firstName: Sam, lastName: Spade, gpa: 2.9, phoneNumber=888-555-1212, skills: [coffee-drinking,Java,Python]] {"firstName":"Jane","lastName":"Deere","areaCode":898,"skills":"[swimming, sleeping, dreaming, kayaking]"}
- creates the studentInfo String array as follows:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started