Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2965 to register SunJaxb21NamespacePrefixMapp for reflection #3033

Merged
merged 1 commit into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import org.apache.camel.converter.jaxb.mapper.SunJaxb21NamespacePrefixMapper;
import org.apache.camel.quarkus.component.jaxb.JaxbRecorder;
import org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem;

Expand All @@ -39,6 +41,11 @@ RuntimeInitializedClassBuildItem fastInfosetStreamWriterOutput() {
return new RuntimeInitializedClassBuildItem(FastInfosetStreamWriterOutput.class.getCanonicalName());
}

@BuildStep
ReflectiveClassBuildItem mapper() {
return new ReflectiveClassBuildItem(false, false, SunJaxb21NamespacePrefixMapper.class);
}

@BuildStep
@Record(value = ExecutionTime.STATIC_INIT)
CamelContextCustomizerBuildItem contextCustomizer(JaxbRecorder recorder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.apache.camel.quarkus.component.jaxb.it;

import java.util.Map;

import javax.xml.bind.JAXBContext;

import org.apache.camel.builder.RouteBuilder;
Expand All @@ -30,6 +32,7 @@ public void configure() throws Exception {
JaxbDataFormat xml = new JaxbDataFormat();
JAXBContext context = JAXBContext.newInstance(Person.class);
xml.setContext(context);
xml.setNamespacePrefix(Map.of("http://example.com/a", "test"));

JaxbDataFormat jaxbFromScheme = new JaxbDataFormat();
jaxbFromScheme.setSchema("classpath:person.xsd");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
@XmlRootElement(name = "person")
public class Person {

@XmlElement(required = true)
@XmlElement(required = true, namespace = "http://example.com/a")
protected String firstName = "John";
@XmlElement(required = true)
@XmlElement(required = true, namespace = "http://example.com/a")
protected String lastName = "Doe";
@XmlElement(required = true, type = Integer.class, nillable = true)
protected Integer age = 33;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void testMarshallFirstName() {
.body("Foo")
.post("/jaxb/marshal-firstname")
.then().statusCode(201).extract().asString();
assertThat(name).contains("<firstName>Foo</firstName>");
assertThat(name).contains("<ns2:firstName>Foo</ns2:firstName>");
}

@Test
Expand All @@ -59,14 +59,14 @@ public void testMarshallLasttName() {
.body("Bar")
.post("/jaxb/marshal-lastname")
.then().statusCode(201).extract().asString();
assertThat(name).contains("<lastName>Bar</lastName>");
assertThat(name).contains("<test:lastName>Bar</test:lastName>");
}

private static String getPersonXml(String name, String lastName, Integer age) {
return String.format(
"<person>" +
"<firstName>%s</firstName>" +
"<lastName>%s</lastName>" +
"<person xmlns:ns2=\"http://example.com/a\">" +
"<ns2:firstName>%s</ns2:firstName>" +
"<ns2:lastName>%s</ns2:lastName>" +
"<age>%d</age>" +
"</person>",
name, lastName, age);
Expand Down