question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Combination of jaxb2-commons-lang toString and attribute default values are not consistant

See original GitHub issue

Imagine 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:closed
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
highsourcecommented, Jul 27, 2016

I guess you’re in the wrong project.

0reactions
ahoehmacommented, Jul 27, 2016

I switched to this configuration and it works like a charm 😃

<plugins combine.children="append">
                <plugin>
                  <groupId>net.java.dev.jaxb2-commons</groupId>
                  <artifactId>jaxb-fluent-api</artifactId>
                  <version>2.1.8</version>
                </plugin>
                <plugin>
                  <groupId>org.jvnet.jaxb2_commons</groupId>
                  <artifactId>jaxb2-basics</artifactId>
                  <version>0.11.1</version>
                </plugin>
              </plugins>
              <args combine.children="merge"> <!-- replace some global stuff -->
                <arg>-no-header</arg> <!-- suppress generation of a file header with timestamp -->
                <arg>-Xfluent-api</arg>
                <arg>-XtoString</arg>
              </args>
  • extra dependency
<!-- Supporting stuff for JAXB generated classes -->
    <dependency>
      <groupId>org.jvnet.jaxb2_commons</groupId>
      <artifactId>jaxb2-basics-runtime</artifactId>
      <version>0.11.1</version>
    </dependency>
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found