【发布时间】:2018-08-04 03:11:58
【问题描述】:
我遇到以下错误:
Security framework of XStream not initialized, XStream is probably vulnerable.
Exception in thread "main" com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field GameList.Game
---- Debugging information ----
message : No such field GameList.Game
field : Game
class : GameList
required-type : GameList
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path : /GameList/Game
line number : 2
version : not available
-------------------------------
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.handleUnknownField(AbstractReflectionConverter.java:524)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:375)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:281)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:70)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134)
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1486)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1466)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1337)
at Start.main(Start.java:11)
我试图在 GameList.xml 文件的 GameList 中获取 Game 对象,但是它总是返回该错误。
Start.java(主要代码):
import com.thoughtworks.xstream.*;
import java.io.*;
import java.util.*;
public class Start {
public static void main(String[] args)throws FileNotFoundException{
XStream xstream = new XStream();
FileReader reader = new FileReader("Games.xml");
GameList gamelist = new GameList();
gamelist.setGames((ArrayList<Game>) xstream.fromXML(reader));
xstream.alias("Game", Game.class);
xstream.alias("Games", GameList.class);
xstream.addImplicitCollection(GameList.class, "Games", Game.class);
}
}
GameList.java 代码:
import java.util.*;
public class GameList {
private ArrayList<Game> Games = new ArrayList<>();
public void setGames(ArrayList<Game> Games2){
Games.clear();
Games2 = Games;
}
}
Game.java 代码:
public class Game {
private int id;
private String name;
private String plataforma;
}
我已经设法让 Xstream 读取非列表类型的简单 xml 代码,但是,我现在需要让它读取带有列表的代码。
【问题讨论】:
标签: xml list arraylist compiler-errors xstream