JSON 从字符串创建对象时对象为空

JSON Object empty when creating it from a String

我正在尝试从字符串创建 JSON 对象。字符串如下所示:{"case":"getAllProducts"}.

为什么 jobj 总是空的?

String received = textMessage.getText();
            
System.out.println(received);       //{"case":"getAllProducts"} - perfect
            
JsonObject jobj = new Gson().fromJson(received, JsonObject.class);
            
System.out.println(jobj);           //{} - why empty???
            
String reqCase = jobj.get("case").getAsString();

我已经在这里查看了其他文章,其中的内容与我完全一样。我在这里找不到我的问题..

而不是

new Gson().fromJson(received, JsonObject.class);

应该是

new Gson().fromJson(received, YourClass.class);

其中 YourClass 是用户定义的 class,其属性与 JSON 中的属性相同。