将json数组反序列化为列表,并保留列表中json的数组顺序 [英] deserialization of a json array to a list and retaining the array order from json within list
本文介绍了将json数组反序列化为列表,并保留列表中json的数组顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下使用杰克逊映射器映射到POJO的json.我如何在反序列化期间保留json中数组列的顺序?我应该使用什么注释?
I have the following json that is mapped to a POJO using Jackson mapper. How do I retain the order of array columns from json during deserialization ? What annotation should I use ?
JSON:
{
"columnNames": [
"FirstName",
"LastName",
"UserName"
],
"values": [
[
"John",
"Smith",
"jsmith"
],
[
"Tim",
"Cook",
"tcook"
]
]
}
POJO:
public class Data implements Serializable {
private List<String> columnNames = new ArrayList<String>();
private List<ArrayList<String>> values = new ArrayList<ArrayList<String>>();
public List<String> getColumnNames() {
return columnNames;
}
public void setColumnNames(List<String> columnNames) {
this.columnNames = columnNames;
}
public List<ArrayList<String>> getValues() {
return values;
}
public void setValues(List<ArrayList<String>> values) {
this.values = values;
}
}
- 预期的getColumnNames():{名字",姓氏",用户名"}
- 实际的getColumnNames():{"UserName","FirstName","LastName"}
我是杰克逊制图的新手,所以我们将不胜感激.
I am new to Jackson mapping so any help is appreciated.
推荐答案
Jackson映射器填充ArrayList并保持JSON的顺序.如果您想要其他订单,则可以使用批注@JsonPropertyOrder.
Jackson mapper fill the ArrayList maintaining the order of JSON. If you want a different order you can use the annotation @JsonPropertyOrder.
这篇关于将json数组反序列化为列表,并保留列表中json的数组顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文