[英]HyperJaxb3 and xsd:anyType
I have a schema fragment that looks like 我有一个看起来像的模式片段
<xs:element name="dataValue">
<xs:complexType>
<xs:sequence>
<xs:element name="value" type="xs:anyType"\>
</xs:sequence>
</xs:complexType>
</xs:element>
The class produced by hyperjaxb3 contains the following fragment: 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;
}
}
I understand that hibernate will struggle to persist a pure Object so hyperjaxb is assuming that the object can be unmarshalled to a XML string and the resultant String is persisted. 据我所知,hibernate将很难持久化纯对象,因此hyperjaxb假设该对象可以被解组为XML字符串并且生成的String是持久的。 In my case this is not true but I can guarantee that the toString() method will return something useful. 在我的情况下,这不是真的,但我可以保证toString()方法将返回一些有用的东西。 I would like the generated code to look more like: 我希望生成的代码看起来更像:
@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();
}
Is there anyway I can get this effect or something similar? 无论如何我可以得到这种效果或类似的东西?
Thanks, 谢谢,
Mark. 标记。
The problem is this conversion must be bidirectional: you must be also able to "parse" your object back from the string - otherwise you won't get the your object back. 问题是这种转换必须是双向的:你必须也能够从字符串中“解析”你的对象 - 否则你将无法获得你的对象。 So toString()
is not enough (but it is such a perfect place to start). 所以toString()
是不够的(但它是一个非常完美的起点)。
I think it can be solved with custom adapters. 我认为可以通过自定义适配器解决。 Ie you write and configure your own adapter for this property. 即,您为此属性编写并配置自己的适配器。 The adapter would do then toString()
/ fromString(...)
for your type. 适配器将为您的类型执行toString()
/ fromString(...)
。
Here's an issue: 这是一个问题:
http://jira.highsource.org/browse/HJIII-54 http://jira.highsource.org/browse/HJIII-54
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.