HyperJaxb3和xsd:anyType

时间:2010-06-23 10:52:53

标签: java xsd jaxb hyperjaxb

我有一个类似

的架构片段
<xs:element name="dataValue">
        <xs:complexType>
            <xs:sequence>           
                <xs:element name="value" type="xs:anyType"\>
            </xs:sequence>
        </xs:complexType>
</xs:element>

hyperjaxb3生成的类包含以下片段:

@XmlElement(required = true)
protected Object value;

@Transient
public Object getValue() {
    return value;
}

public void setValue(Object value) {
    this.value = value;
}

@Basic
@Column(name = "VALUEOBJECT")
public String getValueObject() {
    if (JAXBContextUtils.
       isMarshallable("org.lcogt.schema", this.getValue())) {
        return JAXBContextUtils.unmarshall("org.lcogt.schema", this.getValue());
    } else {
        return null;
    }
}

据我所知,hibernate将难以持久保存纯对象,因此hyperjaxb假设该对象可以被解组为XML字符串并且生成的String是持久的。在我的情况下,这不是真的,但我可以保证toString()方法将返回一些有用的东西。我希望生成的代码看起来更像:

@XmlElement(required = true)
protected Object value;

@Transient
public Object getValue() {
    return value;
}

public void setValue(Object value) {
    this.value = value;
}

@Basic
@Column(name = "VALUEOBJECT")
public String getValueObject() {
      return value.toString();
}

无论如何我可以得到这种效果或类似的东西吗?

谢谢,

标记。

1 个答案:

答案 0 :(得分:0)

问题是这种转换必须是双向的:你必须也能够从字符串中“解析”你的对象 - 否则你将无法获得你的对象。所以toString()是不够的(但它是一个非常完美的起点)。

我认为可以通过自定义适配器解决。即您为此属性编写并配置自己的适配器。然后,适配器会为您的类型toString() / fromString(...)执行此操作。

这是一个问题:

http://jira.highsource.org/browse/HJIII-54

相关问题