views:

47

answers:

1

Hi,

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.

A: 

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. I.e. you write and configure your own adapter for this property. The adapter would do then toString()/fromString(...) for your type.

Here's an issue:

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

lexicore