Jacket too tight? No worries. Stitch your deserialization logic!
Primitives to JsonObject: ticket to the big league
How about making a JsonObject out of a JsonPrimitive? Well, you asked:
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
JsonPrimitive prim = new JsonPrimitive(100);
JsonObject primAsObj = new JsonObject();
primAsObj.add("numberKey", prim);
// Congratulations. A primitive is now part of the big league!
It's like hitting the gym and buffing up for a JsonObject.
JsonElement - Gson's Swiss Army knife
JsonElement — the dependable all-rounder, for those mystery data types:
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
String mysteryData = "[{\"key\":\"value\"},{\"key\":\"another value\"}]";
JsonElement elem = JsonParser.parseString(mysteryData);
if (elem.isJsonArray()) {
// It's an array! The mystery unwrapped.}
No dead ends here! Probe first, then act. Mystery solved, detective.
explain-codes/Java/Gson: Directly convert String to JsonObject (no POJO)