【发布时间】:2017-04-07 15:51:09
【问题描述】:
我需要携带所有 json 数据(存储、记录、返回),但我永远不会从代码中访问它们。有什么方法可以避免反序列化它们但在序列化过程中仍然使用它们?
class MyObject {
int importantField; // i want this field to be properly deserialized
String notImportantJsonGarbage; // i don't care what's here. it must be a valid json
}
所以现在我希望能够反序列化它
{"importantField":7, "notImportantJsonGarbage":{"key1":3, "key2":[1,2,3]}}
稍后将其序列化为相同的字符串
更新
我不想忽略这个属性。我需要这些数据。但作为一个字符串,不是完全反序列化的对象
我需要能够做到:
json1 -> object -> json2
json1 == json2
【问题讨论】:
-
您是否尝试过使用我在回答中提到的 JSONObject 类型?我认为这可以解决您的问题。您可以将其读取到 json 对象并仅在需要时对其进行反序列化。
-
This answer 在另一个反序列化问题上可能会有所帮助。