Combination of jaxb2-commons-lang toString and attribute default values are not consistant
See original GitHub issueImagine you are using this configuration:
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-commons-lang</artifactId>
<version>2.4</version>
</plugin>
</plugins>
<args>
<arg>-no-header</arg> <!-- suppress generation of a file header with timestamp -->
<arg>-Xcommons-lang</arg>
<arg>-Xcommons-lang:ToStringStyle=DEFAULT_STYLE</arg>
</args>
with such a schema:
<xsd:element name="domainpreview-cstic">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="filter" type="DomainPreviewFilter" use="optional" default="ASSIGNABLE"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="DomainPreviewFilter">
<xsd:restriction base="xsd:normalizedString">
<xsd:enumeration value="NONE"/>
<xsd:enumeration value="ASSIGNABLE"/>
</xsd:restriction>
</xsd:simpleType>
Will create this javacode:
public static class DomainpreviewCstic {
@XmlValue
protected String value;
@XmlAttribute(name = "filter")
protected DomainPreviewFilter filter;
...
public DomainPreviewFilter getFilter() {
if (filter == null) {
return DomainPreviewFilter.ASSIGNABLE;
} else {
return filter;
}
}
...
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.DEFAULT_STYLE);
}
And so … If I did’t call getFilter() the filter field is always null and the toString doesn’t shows the “default” value DomainPreviewFilter.ASSIGNABLE.
Is there a way to do this?
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
JAXB2 cannot generate classes for XSD due to ...
I've found an issue with toString generation when using maven-jaxb2-plugin with org.jvnet.jaxb2_commons.jaxb2-basics at version 0.12.0.
Read more >JAXB Users Guide - Java EE
This document explains various interesting/complex/tricky aspects of JAXB, based on questions posted on the JAXB users forum and answers I provided.
Read more >Chapter 38. Customizing How Types are Generated
The JAXB specification defines a number of XML elements that customize how Java types are mapped to XML Schema constructs. These elements can...
Read more >Chapter 17 Binding between XML Schema and Java Classes
This section describes the default XML-to-Java bindings used by JAXB. All of these bindings can be overridden on global or case-by-case levels by...
Read more >Jakarta XML Binding
Support for XML Schema features not required to be supported in JAXB 1.0 has ... the following Java property attributes (common to the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I guess you’re in the wrong project.
I switched to this configuration and it works like a charm 😃