Skip to main content

JAXB2 POJO constraints

2 replies [Last post]
Joined: 2005-09-12

I've generated classes from a schema, and want to add attributes which are not in the .xsd.

The Generate file looks something like this

@XmlType(name = "", propOrder = {"Bar" })
@XmlRootElement(name = "Foo")
public class Foo{

//generated code

@XmlElement(name = "Bar")
protected List fooElement;

// customized code
private String m_attribute = "";


JAXB throws the following error when I do this.

com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Property m_attribute is present but not specified in @XmlType.propOrder

I understand that JAXB is validating the Class' attributes against the schema and is not finding a reference to the m_attribute. But I want to know if there is a way to tell JAXB to ignore the m_attribute when un/marshalling? I would think this would be a necessary feature if there was to be an existing POJO to existing Schema mapping.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2005-09-12

That is what I was looking for. Thanks for the quick response.

Joined: 2003-06-25

Use @XmlTransient i.e.

@XmlTransient private String m_attribute = ... ;