Skip to content

debugOSS/xml2jdto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XML2JDTO

Overview

XML2JDTO is a Java library for converting XML documents to Java DTOs (Data Transfer Objects). It provides utilities for JAXB (Java Architecture for XML Binding) operations, including unmarshalling XML strings into Java objects and schema validation.

Getting Started

Prerequisites

  • Java 21 or higher

  • Maven 3.8.1 or higher

Building the Project

To build the project, run the following command:

mvn clean install

Running Tests

To run the tests, use the following command:

mvn test

Usage

Dependency
<dependency>
    <groupId>io.github.debugoss</groupId>
    <artifactId>xml2jdto-core</artifactId>
    <version>VERSION</version>
</dependency>

Basic function

Marshal and unmarshal XML strings using JAXB
import io.github.debug.xml2jdto.core.jaxb.JaxbUtil;

public class Example {
    public static void main(String[] args) {
        String xml = "<person><name>John Doe</name><age>30</age><address>123 Main St</address></person>";
        // To unmarshal an XML string into a Java object
        Person person = JaxbUtil.unmarshal(xml, Person.class);
        System.out.println(person.getName());
        // To marshal a Java object into an XML string
        String xmlString = JaxbUtil.marshal(person);
        System.out.println(xmlString);
    }
}
Unmarshal XML strings with schema validation
import io.github.debug.xml2jdto.core.jaxb.JaxbUtil;

public class Example {
    public static void main(String[] args) {
        String xml = "<person><name>John Doe</name><age>30</age><address>123 Main St</address></person>";
        String xsdPath = "path/to/schema.xsd";
        Person person = JaxbUtil.unmarshal(xml, Person.class, xsdPath);
        System.out.println(person.getName());
    }
}

Examples

In the example directory, you can find examples of using the XML2JDTO library. The examples demonstrate how to convert XML documents to Java DTOs using JAXB.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

About

XML < - > DTO conversion w/o schema, catalog and customization

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages