首页 \ 问答 \ xstream正在转换&(xstream is converting & to & when converting from xml to Java Objects)

xstream正在转换&(xstream is converting & to & when converting from xml to Java Objects)

xstream正在转换& to & when从xml转换为Java Objects时。 我不希望这种情况发生。 我该怎么办?

 XStream xstream = new XStream(new DomDriver());

            xstream.processAnnotations(HelpConfigVO.class);
            xstream.processAnnotations(ProductVO.class);
            xstream.processAnnotations(PackageVO.class);
            xstream.addImplicitCollection(HelpConfigVO.class, "packages");
            configVO = (HelpConfigVO)xstream.fromXML(helpConfigData);

其次,我从xstream获得的输出XML没有格式化。 如何格式化我的xml以使其可读?


xstream is converting & to & when converting from xml to Java Objects. I don't want this to happen. How shall I do it?

 XStream xstream = new XStream(new DomDriver());

            xstream.processAnnotations(HelpConfigVO.class);
            xstream.processAnnotations(ProductVO.class);
            xstream.processAnnotations(PackageVO.class);
            xstream.addImplicitCollection(HelpConfigVO.class, "packages");
            configVO = (HelpConfigVO)xstream.fromXML(helpConfigData);

Secondly, The output XML I am getting from xstream is not formatted. How do I format my xml to make it readable?


原文:https://stackoverflow.com/questions/8941911
更新时间:2022-03-09 06:03

最满意答案

如果你考虑可能分配给它的东西,一切都是有意义的。

List<? super Number> list1 = new ArrayList<Object>(); // works
List<? super Number> list1 = new ArrayList<Number>(); // works
List<? super Number> list1 = new ArrayList<Integer>(); // doesn't work

任何在右侧工作的东西都会接受Double

List<? super Integer> list = new ArrayList<Object>(); // works
List<? super Integer> list = new ArrayList<Number>(); // works
List<? super Integer> list = new ArrayList<Integer>(); // works

任何你可以分配给list1你也可以分配给list 。 所以list = list1工作得很好。 但并非所有可以分配给list的东西都会接受Double ,所以它不能编译。


Everything makes sense if you consider the possible things you could assign to it.

List<? super Number> list1 = new ArrayList<Object>(); // works
List<? super Number> list1 = new ArrayList<Number>(); // works
List<? super Number> list1 = new ArrayList<Integer>(); // doesn't work

Anything that works on the right hand side will accept a Double.

List<? super Integer> list = new ArrayList<Object>(); // works
List<? super Integer> list = new ArrayList<Number>(); // works
List<? super Integer> list = new ArrayList<Integer>(); // works

Anything that you could assign to list1 you could also assign to list. So list = list1 works just fine. But not all of the things you could assign to list will accept a Double, so it doesn't compile.

相关问答

更多