Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

schemagen.exe doesn't skip @XmlTransient annotated class

Tags:

java

jaxb

xsd

I annotated a XmlAdapter class like so:

@XmlTransient
public class DateTimeXmlAdapter extends XmlAdapter<String, DateTime> {

but schemagen.exe generates

<xs:complexType name="xmlAdapter" abstract="true">
    <xs:sequence/>
  </xs:complexType>

so does't skip the class, which was what I expected. XmlAdapter indeed is an abstract class that my transient class inherits from. What should i do?

The reason I refer in a field to DateTimeXmlAdapter is:

@XmlElement(name="StartDatetime")
@XmlJavaTypeAdapter(DateTimeXmlAdapter.class)
protected DateTime startDatetime;

which is correct I think.

like image 489
Gerard Avatar asked Feb 27 '26 15:02

Gerard


1 Answers

It looks like you've told schemagen to generate schema types for everything in your java package, including the XmlAdapter subclass. It therefore sees your adaptor class, which is marked as @XmlTransient, and therefore doesn't generate a schema type for it. However, it does generate a schema type for XmlAdapter itself.

You need to change how you invoke schemagen so that your adapter class is excluded from the code generation. The @XmlTransient isn't appropriate here, so remove that from the adapter class.

like image 150
skaffman Avatar answered Mar 01 '26 05:03

skaffman