2
我有以下POJO類:傑克遜系列化/樹形結構的反序列化
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Folder", propOrder = {
"id",
"parent"
})
@XmlSeeAlso({
FolderTree.class
})
public class Folder
{
protected int id;
protected int parent;
getters, setters...
}
和
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "FolderTree", propOrder = {
"subFolders"
})
@XmlRootElement(name = "folderTree")
public class FolderTree extends Folder
{
@XmlElement(name = "subFolder", type = Folder.class)
protected List<Folder> subFolders;
getter...
}
和包裝:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Folders", propOrder = {
"folders"
})
@XmlRootElement(name = "folders")
public class Folders
{
@XmlElement(name = "folder", type = Folder.class)
protected List<Folder> folders;
getter...
}
我需要序列化和反序列化他們在XML和JSON中。 XML工作正常,但在JSON以下結構串行化:
{
"folder": [
{
"subFolder": [
{
"subFolder": [],
"id": 2,
"parent": 1
},
{
"subFolder": [],
"id": 3,
"parent": 1
}
],
"id": 1,
"parent": null
}
]
}
解串器不能識別該子文件夾對象(「子文件夾」:[])內的第二場的子文件夾。有沒有辦法讓它只在父文件夾中包含子文件夾字段?或者可以做些什麼來使傑克遜反序列化這個對象?
我無法更改POJO類,因爲它們是由jaxb創建的,並且所有工作都可以正確使用XML。