Converting JSON data to Java object

后端 未结 12 1117
春和景丽
春和景丽 2020-11-21 05:11

I want to be able to access properties from a JSON string within my Java action method. The string is available by simply saying myJsonString = object.getJson()

12条回答
  •  灰色年华
    2020-11-21 05:43

    Bewaaaaare of Gson! It's very cool, very great, but the second you want to do anything other than simple objects, you could easily need to start building your own serializers (which isn't that hard).

    Also, if you have an array of Objects, and you deserialize some json into that array of Objects, the true types are LOST! The full objects won't even be copied! Use XStream.. Which, if using the jsondriver and setting the proper settings, will encode ugly types into the actual json, so that you don't loose anything. A small price to pay (ugly json) for true serialization.

    Note that Jackson fixes these issues, and is faster than GSON.

提交回复
热议问题