Java:FasterXML / jackson反序列化没有键的数组 [英] Java: FasterXML / jackson deserialize array without keys
问题描述
有没有办法如何反序列化JSON数组
Is there a way how to deserialize JSON array
{["a", "b", 1]}
进入以下Java类
class MyObject {
private String firstItem;
private String secondItem;
private int thirdItem;
}
使用FasterXml jackson-databinding?我只找到了数组中有关键值项的答案。
ussing FasterXml jackson-databinding? I only found answers where there are key: value items in the array.
推荐答案
首先 {[ a,b,1]}
不是有效的Json数组(或JSON).... JSON数组看起来像这样 [a,b ,1]
Firstly {["a", "b", 1]}
is not a Valid Json Array (or JSON) .... JSON Array would look like this ["a", "b", 1]
此外,您可以通过为Java对象编写自定义反序列化器并将其注册为Java对象,将Json数组反序列化为Java对象使用更快的Xml模块的对象映射器。
Also you could deserialize the Json Array into a Java Object by writing a Custom Deserializer for the Java Object and Register it with Object Mapper using Module in Faster Xml.
检查以下链接以获取有关如何编写自定义反序列化器的更多信息
Check the Following Link to get more Info on How to write Custom Deserializers
http://www.baeldung.com/jackson-deserialization
我仍然建议不要对对象使用数组表示法。
这篇关于Java:FasterXML / jackson反序列化没有键的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!