Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public boolean canEncode(ResolvableType elementType, @Nullable MimeType mimeType
Class<?> outputClass = elementType.toClass();
return (outputClass.isAnnotationPresent(XmlRootElement.class) ||
outputClass.isAnnotationPresent(XmlType.class) ||
elementType.isAssignableFrom(JAXBElement.class));
JAXBElement.class.isAssignableFrom(outputClass));
}
else {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.http.codec.xml;

import java.io.Serial;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
Expand Down Expand Up @@ -64,6 +65,7 @@ protected void canEncode() {
assertThat(this.encoder.canEncode(forClass(getClass()), MediaType.APPLICATION_XML)).isFalse();

assertThat(this.encoder.canEncode(forClass(JAXBElement.class), MediaType.APPLICATION_XML)).isTrue();
assertThat(this.encoder.canEncode(forClass(JAXBElementSubclass.class), MediaType.APPLICATION_XML)).isTrue();

// SPR-15464
assertThat(this.encoder.canEncode(ResolvableType.NONE, null)).isFalse();
Expand Down Expand Up @@ -122,6 +124,16 @@ protected Consumer<DataBuffer> expectXml(String expected) {
};
}

public static class JAXBElementSubclass extends JAXBElement<Pojo>{
@Serial
private static final long serialVersionUID = 1L;

protected final static QName NAME = new QName("http://foo/schema/common/1.0", "Pojo");
public JAXBElementSubclass() {
super(NAME, Pojo.class, null, null);
}
}

public static class Model {}

public static class Foo extends Model {
Expand Down