Java: FasterXML / jackson deserialize array without keys

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 02:34:06

问题


Is there a way how to deserialize JSON array

{["a", "b", 1]}

into following Java class

class MyObject {
  private String firstItem;
  private String secondItem;
  private int thirdItem;
}

ussing FasterXml jackson-databinding? I only found answers where there are key: value items in the array.


回答1:


Firstly {["a", "b", 1]} is not a Valid Json Array (or JSON) .... JSON Array would look like this ["a", "b", 1]

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

Still I would suggest not using Array Representation for an Object.



来源:https://stackoverflow.com/questions/41719860/java-fasterxml-jackson-deserialize-array-without-keys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!