mizosoft / methanol

⚗️ Lightweight HTTP extensions for Java
https://mizosoft.github.io/methanol
MIT License
239 stars 12 forks source link

Add Jakarta EE JAXB adapters #67

Closed mizosoft closed 9 months ago

mizosoft commented 9 months ago

Closes #65

coveralls commented 9 months ago

Coverage Status

coverage: 91.313% (-0.06%) from 91.369% when pulling af8238e4316ff661e43da8b1113ca70062ff8252 on jaxb-jakarta into 4bc197a09c37b2c8f82ab69e7197c7fb320fcbfc on master.

MarkusWendorf commented 8 months ago

Hi @mizosoft thank you for merging this. Could you tag a new release with this feature?

mizosoft commented 8 months ago

Hey @MarkusWendorf, I'm still working on proper native image support for the next release. In the meantime, feel free to use the snapshot version. This particular feature seems to be finalized for the next release (unless it has any problems, of course). You can use the snapshot from gradle as follows:

repositories {
  mavenCentral()
  maven {
    setUrl("https://oss.sonatype.org/content/repositories/snapshots")
  }
}

dependencies {
  implementation("com.github.mizosoft.methanol:methanol:1.8.0-SNAPSHOT")
  implementation("com.github.mizosoft.methanol:methanol-jaxb-jakarta:1.8.0-SNAPSHOT")
  implementation("com.sun.xml.bind:jaxb-impl:4.0.3")
}

You can install the adapter more easily than previous versions using the new AdapterCodec API:

 var client = Methanol.newBuilder()
        .adapterCodec(AdapterCodec.newBuilder()
            .encoder(JaxbAdapterFactory.createEncoder())
            .decoder(JaxbAdapterFactory.createDecoder())
            .build())
        .build();

    var response = client.send(MutableRequest.GET("https://example.com/data"), MyXmlType.class);
    System.out.println(response.body());

Feel free to provide any feedback.