- 
                Notifications
    You must be signed in to change notification settings 
- Fork 103
JAXB2 ToString Plugin
        Laurent Schoelens edited this page Nov 13, 2023 
        ·
        2 revisions
      
    Adds reflection-free strategy-based toString(...) methods to the schema-derived classes.
Generated classes will implement the org.jvnet.jaxb2_commons.lang.ToString2 (for JAXB2) or org.jvnet.jaxb.lang.ToString (for JAXB3+) interface which, in addition to toString declares append and appendFields methods. Below is an example:
public class SequenceType implements ToString2 {
    // ...
    public String toString() {
        final ToStringStrategy2 strategy = JAXBToStringStrategy.INSTANCE;
        final StringBuilder buffer = new StringBuilder();
        append(null, buffer, strategy);
        return buffer.toString();
    }
    public StringBuilder append(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) {
        strategy.appendStart(locator, this, buffer);
        appendFields(locator, buffer, strategy);
        strategy.appendEnd(locator, this, buffer);
        return buffer;
    }
    public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) {
        {
            String theA;
            theA = this.getA();
            strategy.appendField(locator, this, "a", buffer, theA, this.isSetA());
        }
        {
            Long theB;
            theB = this.getB();
            strategy.appendField(locator, this, "b", buffer, theB, this.isSetB());
        }
        return buffer;
    }
}- Activate the plugin using the -XtoStringswitch.
- 
Optionally provide custom strategy class using -XtoString-toStringStrategyClass=com.acme.foo.MyToStringStrategy(org.jvnet.jaxb2_commons.lang.JAXBToStringStrategyis used by default for JAXB2,org.jvnet.jaxb.lang.JAXBToStringStrategyis used by default for JAXB3+).
- Home
- Migration guide
- 
JAXB Maven Plugin
- Quick Start
- 
User Guide
- Basic Usage
- Specifying What To Compile
- Referencing Resources in Maven Artifacts
- Using Catalogs
- Using Episodes
- Modular Schema Compilation
- Controlling the Output
- Using JAXB Plugins
- Using a Specific JAXB Version
- Configuring Extension, Validation and XML Security
- IDE Integration
- Miscellaneous
- Configuring Proxies
 
- Maven Documentation
- Configuration Cheat Sheet
- Common Pitfalls and Problems
 
- 
JAXB2 Basics Plugins
- Using JAXB2 Basics Plugins
- JSR-305 Support
- 
JAXB2 Basics Plugins List
- SimpleEquals Plugin
- SimpleHashCode Plugin
- Equals Plugin
- HashCode Plugin
- ToString Plugin
- Copyable Plugin
- Mergeable Plugin
- Inheritance Plugin
- AutoInheritance Plugin
- Wildcard Plugin
- Setters Plugin
- Simplify Plugin
- EnumValue Plugin
- JAXBIndex Plugin
- FixJAXB1058 Plugin
- Commons Lang Plugin
- Default Value Plugin
- Fluent API Plugin
- Namespace Prefix Plugin
- Value Constructor Plugin
- Boolean Getter Plugin
- CamelCase Plugin
- XML ElementWrapper Plugin
- Parent Pointer Plugin
- Property Listener Injector Plugin
 
 
- Annox
- JAXB Annotate Plugin
- 
HyperJAXB3
- Build System Support
- Customization Guide
- Databases
- Development guide
- Extension guide
- FAQ
- IDE Support
- Java Persistence
- JAXB
- JDK Support
- Project Templates
- 
Reference
- Adding vendor-specific annotations
- Features
- Integrating Hyperjaxb3 in builds
- Introduction
- Making schema-derived classes ready for JPA
- Adding required properties
- Applying workarounds for JAXB vs. JPA conflicts
- Enforcing top-level classes
- Generating equals and hashCode methods
- Generating ORM metadata
- Generating persistence unit descriptor
- JPA 2 Support
- Making classes serializable
- Testing generated mappings
 
- Reference - single page
- Related Projects
- Sample projects
- Solutions
- Target Scenarios
- Test Projects
- Tutorials
 
- Best Practices
- FAQ
- Sample Projects
- Support
- License
- Distribution