Describe the bug
When using the org.jboss.resteasy.annotations.providers.jaxb.Wrapped annotation in JAX-RS resource to force a specific Collection wrapping XML tag, the collection it not serialized in native mode. However it works as expected in JVM mode.
I use the following code:
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
@Wrapped(element="pastries")
public List<Pastry> getPastries() {
return PastryRepository.getPastries();
}
Expected behavior
When calling my REST endpoint, I expect something like:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<pastries>
<pastry><name>Tartelette Fraise</name><price>2.0</price><size>S</size><status>available</status></pastry>
<pastry><name>Eclair Cafe</name><price>2.5</price><size>M</size><status>available</status></pastry>
<pastry><name>Millefeuille</name><price>4.4</price><size>L</size><status>available</status></pastry>
</pastries>
and that's the result I have when testing in JVM mode.
Actual behavior
When running in native mode, I have the following result:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><pastries/>
When calling REST endpoint that returns single entity (ex: /pastry/{name}), JAXB serialization works as expected even in native mode.
To Reproduce
Steps to reproduce the behavior:
Pastry bean annotated with @RegisterForReflection and @XmlRootElementPastryResource with a method annotated with @Wrapped(element="pastries") and returning a List of PastryI have a demo project here: https://github.com/microcks/api-lifecycle/tree/master/api-pastry-demo/api-implementations/quarkus-api-pastry but it already contains the workaround I found (see below). You will have to remove it first for reproducing the failure.
Configuration
No properties added.
Environment:
uname -a or ver: Darwin lbroudou1-mac 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64java -version: OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.8+10)1.7.1.Finalmvnw --version or gradlew --version): Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)Workaround
Found a workaround by adding a reflection-config.json file and the adhoc native compilation flag. Once added the annotation is well managed in native mode and the serialization works as expected.
[
{
"name" : "org.jboss.resteasy.plugins.providers.jaxb.JaxbCollection",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
},
{
"name" : "javax.xml.bind.annotation.W3CDomHandler",
"allDeclaredConstructors" : true,
"allPublicConstructors" : true,
"allDeclaredMethods" : true,
"allPublicMethods" : true,
"allDeclaredFields" : true,
"allPublicFields" : true
}
]
I think that this setup should be managed within resteasy-jaxb extension as this is a common use-case in RestEasy. If that makes sense for you, I could contribute a PR.
That makes sense to me, PRs very welcome :)
Reading the Writing Extensions guide while building locally the Quarkus modules. Expect PR in few hours / days depending on distractions ;-)
PR #11817 is now submitted