Person person = new Person("John", "Doe", 30); Gson gson = new Gson(); String json = gson.toJson(person); System.out.println(json);
String json = "{\"firstName\":\"John\",\"lastName\":\"Doe\",\"age\":30}"; Gson gson = new Gson(); Person person = gson.fromJson(json, Person.class); System.out.println(person.getLastName());This code takes a JSON string and parses it into a Java object of type "Person" using the Gson library. The "getLastName" method is then called on the object to print the last name to the console. Overall, the com.google.gson.Gson package library is a powerful tool for working with JSON objects in Java, allowing developers to easily convert between Java objects and JSON strings.