|
|
|
@ -18,6 +18,9 @@ package org.springframework.http.converter.xml; |
|
|
|
|
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.xml.namespace.QName; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import jakarta.xml.bind.JAXBElement; |
|
|
|
import jakarta.xml.bind.Marshaller; |
|
|
|
import jakarta.xml.bind.Marshaller; |
|
|
|
import jakarta.xml.bind.Unmarshaller; |
|
|
|
import jakarta.xml.bind.Unmarshaller; |
|
|
|
import jakarta.xml.bind.annotation.XmlAttribute; |
|
|
|
import jakarta.xml.bind.annotation.XmlAttribute; |
|
|
|
@ -93,6 +96,8 @@ class Jaxb2RootElementHttpMessageConverterTests { |
|
|
|
.as("Converter does not support writing @XmlRootElement subclass").isTrue(); |
|
|
|
.as("Converter does not support writing @XmlRootElement subclass").isTrue(); |
|
|
|
assertThat(converter.canWrite(rootElementCglib.getClass(), null)) |
|
|
|
assertThat(converter.canWrite(rootElementCglib.getClass(), null)) |
|
|
|
.as("Converter does not support writing @XmlRootElement subclass").isTrue(); |
|
|
|
.as("Converter does not support writing @XmlRootElement subclass").isTrue(); |
|
|
|
|
|
|
|
assertThat(converter.canWrite(JAXBElement.class, null)) |
|
|
|
|
|
|
|
.as("Converter does not support writing JAXBElement").isTrue(); |
|
|
|
assertThat(converter.canWrite(Type.class, null)) |
|
|
|
assertThat(converter.canWrite(Type.class, null)) |
|
|
|
.as("Converter supports writing @XmlType").isFalse(); |
|
|
|
.as("Converter supports writing @XmlType").isFalse(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -186,6 +191,18 @@ class Jaxb2RootElementHttpMessageConverterTests { |
|
|
|
.isSimilarTo("<rootElement><type s=\"Hello World\"/></rootElement>", ev); |
|
|
|
.isSimilarTo("<rootElement><type s=\"Hello World\"/></rootElement>", ev); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void writeJaxbElementRootElement() throws Exception { |
|
|
|
|
|
|
|
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); |
|
|
|
|
|
|
|
JAXBElement jaxbElement = new JAXBElement<>(new QName("custom"), MyCustomElement.class, new MyCustomElement("field1", "field2")); |
|
|
|
|
|
|
|
converter.write(jaxbElement, null, outputMessage); |
|
|
|
|
|
|
|
assertThat(outputMessage.getHeaders().getContentType()) |
|
|
|
|
|
|
|
.as("Invalid content-type").isEqualTo(MediaType.APPLICATION_XML); |
|
|
|
|
|
|
|
DifferenceEvaluator ev = chain(Default, downgradeDifferencesToEqual(XML_STANDALONE)); |
|
|
|
|
|
|
|
assertThat(XmlContent.of(outputMessage.getBodyAsString(StandardCharsets.UTF_8))) |
|
|
|
|
|
|
|
.isSimilarTo("<custom><field1>field1</field1><field2>field2</field2></custom>", ev); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void writeXmlRootElementSubclass() throws Exception { |
|
|
|
void writeXmlRootElementSubclass() throws Exception { |
|
|
|
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); |
|
|
|
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); |
|
|
|
|