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:
@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. In my case this is not true but I can guarantee that the toString() method will return something useful. 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).
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.
Here's an issue:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.