Nipun Alahakoon
Nipun Alahakoon

Reputation: 2862

JAXB giving an exception when trying to Marshall with given order

i have a code similar to this

@XmlRootElement(name = "root")
@XmlType(propOrder={"param1", "param2""})
public class Demo{
public Demo() {
}
private int param1;
private String param2;
private String param3;



public int getparam1() {
    return param1;
}

@XmlElement
public void setparam1(int param1) {
    this.param1= param1;
}

//other setters and getters here except for param3
}

but it gives me

      n4 counts of IllegalAnnotationExceptions

exception when i try to run the program (i have 6 parameters in total in original code and only 4 is use for Marshall )

What would be the reason for this?

Upvotes: 1

Views: 52

Answers (1)

Matteo Baldi
Matteo Baldi

Reputation: 5828

There is an error in the @XmlType anntation:

@XmlType(propOrder={"param1", "param2","param3"})

If this not fix the problem, try to check the name of the properties in the propOrder OR directly use field accessor type:

@XmlRootElement(name = "root")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder={"param1", "param2", "param3"})
public class Demo{

public Demo() {
}

private int param1;
private String param2;
private String param3;

//getter & setters without annotations

}

Upvotes: 1

Related Questions