Skip to content

πŸš€ Modern JAXB plugins collection for Java XML binding - XJC plugins with JSR-310 date/time support, annotation processing, and code generation tools

License

Notifications You must be signed in to change notification settings

rawvoid/jaxb-plugins

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ JAXB Plugins Collection

Supercharge your XML binding with next-gen JAXB plugins!

Java JAXB License

Tired of boring, boilerplate-heavy JAXB code generation? Say hello to JAXB Plugins Collection – your ultimate toolkit for making XML binding actually fun again! πŸŽ‰

This collection of powerful plugins transforms the way you work with JAXB, giving you superpowers to customize, optimize, and streamline your generated code like never before.


✨ What's Inside?

πŸ”§ Core Framework

Built on a rock-solid foundation with our AbstractPlugin class that makes creating new plugins a breeze. Features annotation-based configuration, automatic option parsing, and extensible text parsers.


🎯 Plugin Arsenal

πŸ“… JSR310Plugin -Xjsr310

Time travel made easy!

Bring your JAXB code into the 21st century with full JSR-310 (java.time) support. Automatically maps XSD date/time types to modern Java time API classes.

πŸ”₯ Use Cases:

  • Use LocalDateTime instead of XMLGregorianCalendar
  • Support ZonedDateTime for timezone-aware dates
  • Custom date formatting with patterns
  • Auto-generate XmlAdapter classes

⚑ Quick Start:

-Xjsr310 \
  -adapter-package=com.example.adapters \
  -mapping \
  -xsd-type=dateTime \
  -target-class=java.time.LocalDateTime \
  -pattern=yyyy-MM-dd HH:mm:ss

πŸ“ Command Structure:

-Xjsr310 \
  -adapter-package=package.name \
  -mapping \
  -xsd-type=xsdType \
  -target-class=java.time.Class \
  -pattern=dateFormat \
  -adapter=custom.AdapterClass \
  -regex=fieldPattern

🎯 Default Mappings:

  • xs:dateTime β†’ LocalDateTime
  • xs:date β†’ LocalDate
  • xs:time β†’ LocalTime
  • xs:gYearMonth β†’ YearMonth
  • xs:gYear β†’ Year
  • xs:gMonthDay β†’ MonthDay
  • xs:gDay β†’ Integer
  • xs:gMonth β†’ Month
  • xs:duration β†’ Duration

🏷️ AnnotatePlugin -Xannotate

Your annotation wizard!

Add, remove, or customize annotations on generated classes, fields, methods, and packages. Perfect for integrating with frameworks like Jackson, Hibernate, or your custom annotations.

πŸ”₯ Use Cases:

  • Add @JsonProperty annotations for JSON serialization
  • Inject validation annotations (@NotNull, @Size)
  • Add Lombok annotations (@Data, @Builder, @Accessor)
  • Remove unwanted JAXB annotations
  • Apply custom framework annotations

⚑ Quick Start:

-Xannotate \
  -add-to-class \
  -anno=@com.example.MyAnnotation \
  -regex=.*Person \
  -add-to-field \
  -anno=@com.fasterxml.jackson.annotation.JsonProperty("value") \
  -regex=.*name

πŸ“ Command Structure:

-Xannotate \
  -add-to-class|-add-to-field|-add-to-method|-add-to-package \
  -anno=@AnnotationClass(param="value") \
  -regex=pattern \
  -remove-from-class|-remove-from-field|-remove-from-method|-remove-from-package \
  -anno=AnnotationClass \
  -regex=pattern

πŸ”„ ConvertNamePlugin -Xconvert-name

The naming ninja!

Take control of how JAXB converts XML names to Java identifiers. Customize class names, field names, method names, and package names with precision.

πŸ”₯ Use Cases:

  • Convert snake_case XML to camelCase Java
  • Apply custom naming conventions
  • Fix awkward auto-generated names
  • Map legacy XML to modern Java standards

⚑ Quick Start:

-Xconvert-name \
  -class-name \
  -token=XMLDocument \
  -name=Document \
  -variable-name \
  -regex=(.*)_ID \
  -name=$1Id

πŸ“ Command Structure:

-Xconvert-name \
  -class-name|-variable-name|-interface-name|-property-name|-constant-name|-package-name \
  -token=originalName \
  -regex=pattern \
  -name=newName

πŸ“¦ ElementWrapperPlugin -Xelement-wrapper

The wrapper eliminator!

Simplify your generated code by automatically flattening wrapper classes. Moves @XmlElementWrapper and @XmlElement annotations to the using field and optionally removes the wrapper class entirely.

πŸ”₯ Use Cases:

  • Clean up collection wrapper classes
  • Reduce boilerplate code
  • Improve API readability
  • Optimize memory usage

⚑ Quick Start:

-Xelement-wrapper \
  -remove-wrapper-class=true

🌍 NamespacePlugin -Xnamespace

The namespace navigator!

This plugin is deprecated and may be removed in future versions.

Take control of XML namespace to Java package mappings. Define custom mappings and automatically generate JAXB binding files.

πŸ”₯ Use Cases: - Map namespaces to meaningful package names - Avoid default package naming conflicts - Support multiple schema versions - Clean up package structure

⚑ Quick Start:

-Xnamespace \
  -mapping \
  -ns=http://example.com/schema \
  -package=com.example.schema \
  -prefix=ex

πŸ“ Command Structure:

-Xnamespace \
  -mapping \
  -ns=namespaceURI \
  -package=java.package.name \
  -prefix=xmlPrefix

πŸ—‘οΈ RemoveGetterPlugin -Xremove-getter

The getter ghost!

Remove unnecessary getter methods from generated classes when you only need setters or direct field access.

πŸ”₯ Use Cases:

  • Create immutable-like structures
  • Reduce method count for cleaner APIs
  • Optimize for specific use cases
  • Custom access patterns

⚑ Quick Start:

-Xremove-getter

πŸ—‘οΈ RemoveSetterPlugin -Xremove-setter

The setter slayer!

Remove unnecessary setter methods from generated classes when you only need getters or want read-only objects.

πŸ”₯ Use Cases:

  • Create read-only DTOs
  • Enforce immutability
  • Secure data transfer objects
  • Clean API design

⚑ Quick Start:

-Xremove-setter

🏷️ NsPrefixPlugin -Xns-prefix

The namespace prefix master!

Take control of XML namespace prefixes in generated @XmlSchema annotations. Define custom mappings between XML namespaces and their prefixes, and automatically update package-info.java files.

πŸ”₯ Use Cases:

  • Set consistent XML namespace prefixes across generated code
  • Customize prefixes for specific packages using regex patterns
  • Manage multiple namespaces in complex XML schemas
  • Replace default JAXB-generated prefixes with meaningful ones

⚑ Quick Start:

-Xns-prefix \
  -config \
  -xmlns \
  -ns=http://example.com \
  -prefix=ex

πŸ“ Command Structure:

-Xns-prefix \
  -config \
    -package=package.regex.pattern \
    -xmlns \
    -ns=namespaceURI \
    -prefix=xmlPrefix \
    -xmlns \
    -ns=anotherNamespace \
    -prefix=anotherPrefix \
  -config \
    -package=another.package.regex \
    -xmlns \
    -ns=namespaceURI \
    -prefix=prefix

🎯 Advanced Examples:

# Apply to all packages
-Xns-prefix -config -xmlns -ns=http://example.com -prefix=ex

# Package-specific configuration
-Xns-prefix -config -package=com\.example\.* -xmlns -ns=http://example.com -prefix=ex

# Multiple namespaces for a package
-Xns-prefix -config -package=com\.example\.* -xmlns -ns=http://example.com -prefix=ex -xmlns -ns=http://test.com -prefix=tst

πŸš€ Getting Started

πŸ“¦ Installation

Add this to your Maven pom.xml:

<dependency>
    <groupId>io.github.rawvoid</groupId>
    <artifactId>jaxb-plugins</artifactId>
    <version>1.0.0</version>
</dependency>

πŸ”§ Maven Plugin Setup

<plugin>
    <groupId>org.jvnet.jaxb</groupId>
    <artifactId>jaxb-maven-plugin</artifactId>
    <version>4.0.12</version>
    <configuration>
        <plugins>
            <plugin>
                <groupId>io.github.rawvoid</groupId>
                <artifactId>jaxb-plugins</artifactId>
                <version>1.0.0</version>
            </plugin>
        </plugins>
        <args>
            <arg>-Xjsr310</arg>
            <arg>-Xannotate</arg>
            <arg>-Xconvert-name</arg>
            <arg>-Xns-prefix</arg>
        </args>
    </configuration>
</plugin>

🎯 Command Line Usage

xjc -d src -p com.example \
    -extension \
    -Xjsr310 \
    -Xannotate \
    -Xconvert-name \
    -Xns-prefix \
    schema.xsd

🎨 Advanced Examples

🌟 Full Stack Example

xjc schema.xsd \
  -d src/main/java \
  -p com.example.api \
  -extension \
  -Xjsr310 \
    -adapter-package=com.example.adapters \
    -mapping \
    -xsd-type=dateTime \
    -target-class=java.time.LocalDateTime \
  -Xannotate \
    -add-to-class \
    -anno=@com.fasterxml.jackson.annotation.JsonInclude(JsonInclude.Include.NON_NULL) \
    -add-to-field \
    -anno=@com.fasterxml.jackson.annotation.JsonProperty("value") \
    -regex=.*\.value \
  -Xconvert-name \
    -class-name \
    -regex=(.*)Type \
    -name=$1DTO \
    -variable-name \
    -regex=(.*)_ID \
    -name=$1Id \
  -Xnamespace \
    -mapping \
    -ns=http://api.example.com \
    -package=com.example.api

πŸ”₯ Microservice Example

xjc -d src \
  -Xjsr310 \
    -mapping \
    -xsd-type=dateTime \
    -target-class=java.time.Instant \
    -mapping \
    -xsd-type=date \
    -target-class=java.time.LocalDate \
    -pattern=yyyy-MM-dd \
  -Xelement-wrapper \
    -remove-wrapper-class=true \
  -Xremove-getter \
  schema.xsd

β˜• Lombok Integration Example

xjc schema.xsd \
  -d src/main/java \
  -p com.example.domain \
  -extension \
  -Xannotate \
    -add-to-class \
    -anno=@lombok.Data \
    -anno=@lombok.experimental.Accessor(chain = true) \
    -regex=.* \
  -Xremove-getter \
  -Xremove-setter

🎯 What this does:

  • Adds @Data annotation to all generated classes (generates getters, setters, toString, equals, hashCode)
  • Adds @Accessor(chain = true) for fluent builder pattern
  • Removes JAXB-generated getter methods (replaced by Lombok)
  • Removes JAXB-generated setter methods (replaced by Lombok)
  • Results in clean, modern Java classes with Lombok-powered functionality

πŸ› οΈ Building from Source

git clone https://github.com/rawvoid/jaxb-plugins.git
cd jaxb-plugins
mvn clean install

Requirements:

  • Java 21+
  • Maven 3.6+

🀝 Contributing

Got an awesome plugin idea? Found a bug? Want to make things even better? We'd love your help! πŸŽ‰

  1. Fork this repo
  2. Create your feature branch (git checkout -b feature/amazing-plugin)
  3. Commit your changes (git commit -m 'Add mind-blowing plugin')
  4. Push to the branch (git push origin feature/amazing-plugin)
  5. Open a Pull Request

πŸ“œ License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.


🌟 Star History

Star History Chart


πŸ’¬ Got Questions?


πŸ™ Acknowledgments


⭐ If this project made your JAXB life easier, give it a star! ⭐

Made with β˜• and 🎡 by Rawvoid

About

πŸš€ Modern JAXB plugins collection for Java XML binding - XJC plugins with JSR-310 date/time support, annotation processing, and code generation tools

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages