From 307fb0aec8c455d4c24aedb07e54e523bbf09428 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Mon, 27 Jul 2009 11:15:43 +0000 Subject: [PATCH] SPR-5942: MarshallingHttpMessageConverter should not require both marshaller and unmarshaller --- .../xml/MarshallingHttpMessageConverter.java | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/org.springframework.web/src/main/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverter.java b/org.springframework.web/src/main/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverter.java index 46e87c67cda..05a1bc4407c 100644 --- a/org.springframework.web/src/main/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverter.java +++ b/org.springframework.web/src/main/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverter.java @@ -20,7 +20,6 @@ import java.io.IOException; import javax.xml.transform.Result; import javax.xml.transform.Source; -import org.springframework.beans.factory.InitializingBean; import org.springframework.http.HttpHeaders; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotWritableException; @@ -44,8 +43,7 @@ import org.springframework.util.Assert; * @author Arjen Poutsma * @since 3.0 */ -public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConverter - implements InitializingBean { +public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConverter { private Marshaller marshaller; @@ -66,18 +64,11 @@ public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConve * {@code Unmarshaller} interface, so that you can safely use this constructor. * * @param marshaller object used as marshaller and unmarshaller - * @throws IllegalArgumentException when marshaller does not implement the {@link Unmarshaller} interface - * as well */ public MarshallingHttpMessageConverter(Marshaller marshaller) { Assert.notNull(marshaller, "marshaller must not be null"); - if (!(marshaller instanceof Unmarshaller)) { - throw new IllegalArgumentException("Marshaller [" + marshaller + "] does not implement the Unmarshaller " + - "interface. Please set an Unmarshaller explicitely by using the " + - "MarshallingHttpMessageConverter(Marshaller, Unmarshaller) constructor."); - } - else { - this.marshaller = marshaller; + this.marshaller = marshaller; + if (marshaller instanceof Unmarshaller) { this.unmarshaller = (Unmarshaller) marshaller; } } @@ -106,17 +97,13 @@ public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConve this.unmarshaller = unmarshaller; } - public void afterPropertiesSet() { - Assert.notNull(this.marshaller, "Property 'marshaller' is required"); - Assert.notNull(this.unmarshaller, "Property 'unmarshaller' is required"); - } - public boolean supports(Class clazz) { return unmarshaller.supports(clazz); } @Override protected Object readFromSource(Class clazz, HttpHeaders headers, Source source) throws IOException { + Assert.notNull(this.unmarshaller, "Property 'unmarshaller' is required"); try { return unmarshaller.unmarshal(source); } @@ -127,6 +114,7 @@ public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConve @Override protected void writeToResult(Object o, HttpHeaders headers, Result result) throws IOException { + Assert.notNull(this.marshaller, "Property 'marshaller' is required"); try { marshaller.marshal(o, result); }