This repository contains the implementation of a lab using the Gson library for JSON serialization, deserialization, and making API calls. The lab is divided into three main tasks:
- JSON Serialization
- JSON Deserialization
- API Call
- Java Development Kit (JDK) 8 or higher
- Maven or Gradle for dependency management
-
Clone the repository:
git clone https://github.com/timGalk/Lab10-IOOP.git
-
Navigate to the project directory:
cd gson-lab
-
Add Gson dependency to your
pom.xml
(for Maven) orbuild.gradle
(for Gradle):For Maven:
<dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.11.0</version> </dependency>
For Gradle:
implementation group: 'com.google.code.gson', name: 'gson', version: '2.11.0'
- Create a
CastMember
class withactorName
andcharacterName
properties. - Create a
Movie
class withtitle
,directorName
,duration
, andcast
properties. - In the
Main
class, create a list of at least two movies, each with at least two cast members. - Convert the list of movies into JSON with pretty printing enabled.
- Print the result of the serialization to the console.
- Define
Student
andCourse
classes to represent the structure of thestudents.json
file. - Read the
students.json
file and convert its content into a list ofStudent
objects. - Calculate and print the average grade from all courses for each student.
- Find and print the student with the highest average grade.
- Create a
JokeApiClient
class with a methodjokeApiRequest
that sends a GET request to a joke API and returns the body of the response. - Define a
Joke
class that represents the structure of the joke API’s response. - In a testing method, call the
jokeApiRequest
method, convert the result into aJoke
object, and print the object to the console.
- Ensure all dependencies are installed.
- Compile the project using your IDE or command line.
- Run the
Main
class to see the output of the serialization and deserialization tasks. - The API call task can be tested by running the respective method in the
JokeApiClient
class.