我使用Jackson-jr來閱讀我的JSON文件。其中之一是一個有點複雜:Jackson-jr閱讀多態ArrayList
[
{"test-1":["a","b","c","d"]},
{"test-2":["b","j","d"]},
{"test-3":["n","e","o","p","i"]},
{"test-4":["s","a","v","z","b","ç","x","p"]},
{"test-5":["d","q","u"]},
{"test-6":["f","b"]}
]
我的代碼來讀取很簡單:
InputStream inputStream = assetManager.open("test.json");
ArrayList<HashMap<String, ArrayList<String>>> arrays = JSON.std.beanFrom(ArrayList.class, inputStream);
我的目的是讓每個陣列與他們每個人的工作:
arrays.get(i);
但是,當這條線被執行時,我有一個例外:
Caused by: java.lang.ClassCastException: com.fasterxml.jackson.jr.ob.impl.DeferredMap cannot be cast to java.util.HashMap
Jackson-jr沒有TypeFactory,TypeReference或ObjectMapper。一些鏈接,我發現答案傑克遜,而不是傑克遜JR:
ClassCastException when convert json to list of objects
Jackson custom deserializer for one field with polymorphic types
Tricky(?) JSON, polymorphic deserialization
有沒有說,在傑克遜JR來處理呢?
定義'arrays'爲'名單<地圖<字符串,列表 >> arrays' –
sidgate
您保存一天。謝謝。 – learner