Skip to content

Latest commit

 

History

History
69 lines (51 loc) · 1.35 KB

README.md

File metadata and controls

69 lines (51 loc) · 1.35 KB

xml-jaxb

This module provides support to application/xml using jax-b, a Java API to process XML content.

Install

Maven

<dependency>
    <groupId>com.github.ljtfreitas.julian-http-client</groupId>
    <artifactId>julian-http-client-xml-jaxb</artifactId>
    <version>${julian-http-client-version}</version>
</dependency>

Gradle

dependencies {
    implementation("com.github.ljtfreitas.julian-http-client:julian-http-client-xml-jaxb:$julianHttpClientVersion")
}

Usage

import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "person")
class Person {

    @XmlElement
    String name;

    @XmlElement
    int age;

    Person() {
    }

    Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
}

@XmlRootElement(name = "person")
class PersonResponse {

    @XmlElement
    int id;

    @XmlElement
    String name;

    @XmlElement
    int age;
}

@Path("/person")
interface PersonApi {

    @POST
    PersonResponse create(@Body("application/xml") Person person); // a body with application/xml content-type will be serialized by jax-b

    @GET("/{personId}")
    PersonResponse get(@Path int personId); // a response with application/xml content-type will be deserialized by jax-b
}