20
20
import javax .xml .transform .Result ;
21
21
import javax .xml .transform .Source ;
22
22
23
- import org .springframework .beans .factory .InitializingBean ;
24
23
import org .springframework .http .HttpHeaders ;
25
24
import org .springframework .http .converter .HttpMessageNotReadableException ;
26
25
import org .springframework .http .converter .HttpMessageNotWritableException ;
44
43
* @author Arjen Poutsma
45
44
* @since 3.0
46
45
*/
47
- public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConverter <Object >
48
- implements InitializingBean {
46
+ public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConverter <Object > {
49
47
50
48
private Marshaller marshaller ;
51
49
@@ -66,18 +64,11 @@ public MarshallingHttpMessageConverter() {
66
64
* {@code Unmarshaller} interface, so that you can safely use this constructor.
67
65
*
68
66
* @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
71
67
*/
72
68
public MarshallingHttpMessageConverter (Marshaller marshaller ) {
73
69
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 ) {
81
72
this .unmarshaller = (Unmarshaller ) marshaller ;
82
73
}
83
74
}
@@ -106,17 +97,13 @@ public void setUnmarshaller(Unmarshaller unmarshaller) {
106
97
this .unmarshaller = unmarshaller ;
107
98
}
108
99
109
- public void afterPropertiesSet () {
110
- Assert .notNull (this .marshaller , "Property 'marshaller' is required" );
111
- Assert .notNull (this .unmarshaller , "Property 'unmarshaller' is required" );
112
- }
113
-
114
100
public boolean supports (Class <?> clazz ) {
115
101
return unmarshaller .supports (clazz );
116
102
}
117
103
118
104
@ Override
119
105
protected Object readFromSource (Class <Object > clazz , HttpHeaders headers , Source source ) throws IOException {
106
+ Assert .notNull (this .unmarshaller , "Property 'unmarshaller' is required" );
120
107
try {
121
108
return unmarshaller .unmarshal (source );
122
109
}
@@ -127,6 +114,7 @@ protected Object readFromSource(Class<Object> clazz, HttpHeaders headers, Source
127
114
128
115
@ Override
129
116
protected void writeToResult (Object o , HttpHeaders headers , Result result ) throws IOException {
117
+ Assert .notNull (this .marshaller , "Property 'marshaller' is required" );
130
118
try {
131
119
marshaller .marshal (o , result );
132
120
}
0 commit comments