users@jaxb.java.net

Ummarshalling to Object type

From: zeiss <zeiss_at_tut.by>
Date: Sun, 2 May 2010 00:49:21 -0700 (PDT)

Hi,

I need to unmarshal XML element value to a field of type Object. I also
would like JAXB implementation to automatically handle type information I
provide in XML with xsi:type attribute. The result would be an object of
corresponding type as defined by XML data types to Java classes mapping.

Unfortunately, JAXB implementation that I am using (JAXB RI 2.2) seems to
ignore xsi:type in my case. It always creates an object of type String. I am
wondering if I can get the desired result at all when using xsi:type
information.

Here is a simple sample:

<field name="field1" xsi:type="xs:integer"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema">1</field>

@XmlRootElement(name = "field")
public class Field {

  private String name;

  private Object value;

  @XmlAttribute(name = "name")
  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  @XmlValue
  @XmlSchemaType(name = "anySimpleType")
  public Object getValue() {
    return value;
  }

  public void setValue(Object value) {
    this.value = value;
  }
}
-- 
View this message in context: http://old.nabble.com/Ummarshalling-to-Object-type-tp28425349p28425349.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.