为什么JAXB没有写出SWT Widgets? [英] Why doesn't JAXB writes out SWT Widgets?

查看:74
本文介绍了为什么JAXB没有写出SWT Widgets?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类来存储SWT小部件列表。

I have a class to store a list of SWT widgets.

@XmlRootElement
class Test {
    private List<Widget> widgets;

    public List<Widget> getWidgets() {
        return widgets;
    }

    public void setWidgets(List<Widget> widgets) {
        this.widgets = widgets;
    }
}

我使用JAXB将其编组为XML。但是,这些小部件不会被编组。

I used JAXB to marshall it into XML. However, these widgets are not marshalled.

Test t = new Test();
t.setWidgets(widgets);
JAXBContext context = JAXBContext.newInstance(Test.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.marshal(t, System.out);

这是输出:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<test>
    <widgets/>
    <widgets/>
    <widgets/>
</test>


推荐答案

你的 JAXB(JSR-222) 实现无法确定的子类小部件使用反射,因此在创建JAXBContext时需要包含它们。

Your JAXB (JSR-222) implementation can't determine the subclasses of Widget using reflection, so you will need to include them when you create your JAXBContext.

JAXBContext context = JAXBContext.newInstance(Test.class, Button.class, Label.class);

这篇关于为什么JAXB没有写出SWT Widgets?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆