import com.google.gson.Gson;
public class JsonSerializationExample {
public static void main(String[] args) {
Student student = new Student("Alice", 18);
Gson gson = new Gson();
String json = gson.toJson(student);
System.out.println("Serialized JSON: " + json);
Student deserializedStudent = gson.fromJson(json, Student.class);
System.out.println("Deserialized Student: " + deserializedStudent);
}
static class Student {
private String name;
private int age;
@Override
public String toString() {
return "Student{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
}