Which class in GSON is primarily used for JSON serialization and deserialization?
A) Gson
B) JsonObject
C) JsonParser
D) JsonElement
Answer:
A) Gson
Explanation:
The Gson
class is the core class in the GSON library that is primarily used for JSON serialization and deserialization. It provides methods for converting Java objects to JSON strings and JSON strings back to Java objects.
For example:
Gson gson = new Gson();
String json = gson.toJson(someObject);
SomeClass obj = gson.fromJson(json, SomeClass.class);
In this example, the Gson
object is used to serialize a Java object to a JSON string and deserialize a JSON string back to a Java object of type SomeClass
.