Skip to content

Commit 307fb0a

Browse files
committed
SPR-5942: MarshallingHttpMessageConverter should not require both marshaller and unmarshaller
1 parent ac56f1f commit 307fb0a

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

org.springframework.web/src/main/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverter.java

+5-17
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import javax.xml.transform.Result;
2121
import javax.xml.transform.Source;
2222

23-
import org.springframework.beans.factory.InitializingBean;
2423
import org.springframework.http.HttpHeaders;
2524
import org.springframework.http.converter.HttpMessageNotReadableException;
2625
import org.springframework.http.converter.HttpMessageNotWritableException;
@@ -44,8 +43,7 @@
4443
* @author Arjen Poutsma
4544
* @since 3.0
4645
*/
47-
public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConverter<Object>
48-
implements InitializingBean {
46+
public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConverter<Object> {
4947

5048
private Marshaller marshaller;
5149

@@ -66,18 +64,11 @@ public MarshallingHttpMessageConverter() {
6664
* {@code Unmarshaller} interface, so that you can safely use this constructor.
6765
*
6866
* @param marshaller object used as marshaller and unmarshaller
69-
* @throws IllegalArgumentException when <code>marshaller</code> does not implement the {@link Unmarshaller} interface
70-
* as well
7167
*/
7268
public MarshallingHttpMessageConverter(Marshaller marshaller) {
7369
Assert.notNull(marshaller, "marshaller must not be null");
74-
if (!(marshaller instanceof Unmarshaller)) {
75-
throw new IllegalArgumentException("Marshaller [" + marshaller + "] does not implement the Unmarshaller " +
76-
"interface. Please set an Unmarshaller explicitely by using the " +
77-
"MarshallingHttpMessageConverter(Marshaller, Unmarshaller) constructor.");
78-
}
79-
else {
80-
this.marshaller = marshaller;
70+
this.marshaller = marshaller;
71+
if (marshaller instanceof Unmarshaller) {
8172
this.unmarshaller = (Unmarshaller) marshaller;
8273
}
8374
}
@@ -106,17 +97,13 @@ public void setUnmarshaller(Unmarshaller unmarshaller) {
10697
this.unmarshaller = unmarshaller;
10798
}
10899

109-
public void afterPropertiesSet() {
110-
Assert.notNull(this.marshaller, "Property 'marshaller' is required");
111-
Assert.notNull(this.unmarshaller, "Property 'unmarshaller' is required");
112-
}
113-
114100
public boolean supports(Class<?> clazz) {
115101
return unmarshaller.supports(clazz);
116102
}
117103

118104
@Override
119105
protected Object readFromSource(Class<Object> clazz, HttpHeaders headers, Source source) throws IOException {
106+
Assert.notNull(this.unmarshaller, "Property 'unmarshaller' is required");
120107
try {
121108
return unmarshaller.unmarshal(source);
122109
}
@@ -127,6 +114,7 @@ protected Object readFromSource(Class<Object> clazz, HttpHeaders headers, Source
127114

128115
@Override
129116
protected void writeToResult(Object o, HttpHeaders headers, Result result) throws IOException {
117+
Assert.notNull(this.marshaller, "Property 'marshaller' is required");
130118
try {
131119
marshaller.marshal(o, result);
132120
}

0 commit comments

Comments
 (0)