Child class properties do not map to parent class properties in JAXB

I can't figure out why the properties of the child class don't map to the properties of the parent class. The values ​​for the parent class are zero. Should there be an explicit property conversion? I suspect it shouldn't be. I believe I am not using the correct XML annotation. Any help would be greatly appreciated.

-C

Main:

Converter converter = new Converter(ChildClass.COSTAR);

      

Converter class

public Converter(ParentClass iClass)
{
    mClass = iClass;
}

      

Values ​​from the debugger:

mName = {java.lang.String@724}"Costar" // Child class
mRows = {java.lang.String@725}"16"     // Child class
mCols = {java.lang.String@726}"24"     // Child class
value = null                           // Parent class
columns = null                         // Parent class
rows = null                            // Parent class

      

Parent class:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ParentClass", propOrder = {
"value"
})
public class ParentClass {

@XmlValue
protected String value;
@XmlAttribute
protected String columns;
@XmlAttribute
protected String rows;

public String getValue() {
    return value;
}

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

public String getRows() {
    return rows;
}

public void setRows(String value) {
    this.rows = value;
}

public String getColumns() {
    return columns;
}

public void setColumns(String value) {
    this.columns = value;
}

}

      

Child class:

public class ChildClass
       extends ParentClass
{

public static final ChildClass COSTAR = new ChildClass("Costar", 16, 24);

public static final ChildClass LOSTAR = new ChildClass("Lostar",8,12);

public static final ChildClass JOSTAR = new ChildClass("Jostar",16,24);

@XmlValue
private String mName;
@XmlAttribute
private String mRows;
@XmlAttribute
private String mCols;

public ChildClass(String iName, int iRows, int iCols)
{
    if(iName == null)
    {
       throw new IllegalArgumentException("Cannot pass in null name");
    }

    if(iRows<1)
    {
       throw new IllegalArgumentException("Invalid plate row dimension: " + iRows);
    }

    if(iCols<1)
    {
       throw new IllegalArgumentException("Invalid plate column dimension: " + iCols);
    }

    mName = iName;
    mRows = String.valueOf(iRows);
    mCols = String.valueOf(iCols);

}

@Override
public String getValue()
{
    return mName;
}

@Override
public void setValue(String value)
{
    throw new IllegalArgumentException("Cannot reset plate mName");
}

@Override
public String getRows()
{
    return mRows;
}

@Override
public void setRows(String value)
{
    throw new IllegalArgumentException("Cannot reset plate mRows");
}

@Override
public String getColumns()
{
    return mCols;
}

@Override
public void setColumns(String value)
{
    throw new IllegalArgumentException("Cannot reset plate cols");
}

}

      

EDIT:

When using the debugger, it does not display the Child class that runs on the Parent class. It remains as an object of the Child class.

+3


source to share


1 answer


add the following annotation to ParentClass

:



@XmlSeeAlso({ChildClass.class})

      

0


source







All Articles