本文整理汇总了Java中org.springframework.oxm.Marshaller类的典型用法代码示例。如果您正苦于以下问题:Java Marshaller类的具体用法?Java Marshaller怎么用?Java Marshaller使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Marshaller类属于org.springframework.oxm包,在下文中一共展示了Marshaller类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeWithMarshallingFailureException
import org.springframework.oxm.Marshaller; //导入依赖的package包/类
@Test
public void writeWithMarshallingFailureException() throws Exception {
String body = "<root>Hello World</root>";
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
MarshallingFailureException ex = new MarshallingFailureException("forced");
Marshaller marshaller = mock(Marshaller.class);
willThrow(ex).given(marshaller).marshal(eq(body), isA(Result.class));
try {
MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller);
converter.write(body, null, outputMessage);
fail("HttpMessageNotWritableException should be thrown");
}
catch (HttpMessageNotWritableException e) {
assertTrue("Invalid exception hierarchy", e.getCause() == ex);
}
}
示例2: MarshallingHttpMessageConverter
import org.springframework.oxm.Marshaller; //导入依赖的package包/类
/**
* Construct a new {@code MarshallingMessageConverter} with the given
* {@code Marshaller} and {@code Unmarshaller}.
* @param marshaller the Marshaller to use
* @param unmarshaller the Unmarshaller to use
*/
public MarshallingHttpMessageConverter(Marshaller marshaller, Unmarshaller unmarshaller) {
Assert.notNull(marshaller, "Marshaller must not be null");
Assert.notNull(unmarshaller, "Unmarshaller must not be null");
this.marshaller = marshaller;
this.unmarshaller = unmarshaller;
}
示例3: marshalToString
import org.springframework.oxm.Marshaller; //导入依赖的package包/类
public static String marshalToString(@Nonnull final Object data, @Nonnull final Marshaller marshaller) {
Objects.requireNonNull(data, "data must not be null");
Objects.requireNonNull(marshaller, "marshaller must not be null");
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
marshaller.marshal(data, new StreamResult(baos));
return new String(baos.toByteArray(), Constants.DEFAULT_ENCODING);
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
示例4: MarshallingMessageConverter
import org.springframework.oxm.Marshaller; //导入依赖的package包/类
/**
* Constructor with {@link Marshaller}. If the given {@link Marshaller} also
* implements {@link Unmarshaller}, it is also used for unmarshalling.
* <p>Note that all {@code Marshaller} implementations in Spring also implement
* {@code Unmarshaller} so that you can safely use this constructor.
* @param marshaller object used as marshaller and unmarshaller
*/
public MarshallingMessageConverter(Marshaller marshaller) {
this();
Assert.notNull(marshaller, "Marshaller must not be null");
this.marshaller = marshaller;
if (marshaller instanceof Unmarshaller) {
this.unmarshaller = (Unmarshaller) marshaller;
}
}
示例5: canWrite
import org.springframework.oxm.Marshaller; //导入依赖的package包/类
@Test
public void canWrite() throws Exception {
Marshaller marshaller = mock(Marshaller.class);
given(marshaller.supports(Integer.class)).willReturn(false);
given(marshaller.supports(String.class)).willReturn(true);
MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter();
converter.setMarshaller(marshaller);
assertFalse(converter.canWrite(Boolean.class, MediaType.TEXT_PLAIN));
assertFalse(converter.canWrite(Integer.class, MediaType.TEXT_XML));
assertTrue(converter.canWrite(String.class, MediaType.TEXT_XML));
}
示例6: readWithTypeMismatchException
import org.springframework.oxm.Marshaller; //导入依赖的package包/类
@Test(expected = TypeMismatchException.class)
public void readWithTypeMismatchException() throws Exception {
MockHttpInputMessage inputMessage = new MockHttpInputMessage(new byte[0]);
Marshaller marshaller = mock(Marshaller.class);
Unmarshaller unmarshaller = mock(Unmarshaller.class);
given(unmarshaller.unmarshal(isA(StreamSource.class))).willReturn(Integer.valueOf(3));
MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller, unmarshaller);
converter.read(String.class, inputMessage);
}
示例7: write
import org.springframework.oxm.Marshaller; //导入依赖的package包/类
@Test
public void write() throws Exception {
String body = "<root>Hello World</root>";
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
Marshaller marshaller = mock(Marshaller.class);
willDoNothing().given(marshaller).marshal(eq(body), isA(Result.class));
MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller);
converter.write(body, null, outputMessage);
assertEquals("Invalid content-type", new MediaType("application", "xml"), outputMessage.getHeaders()
.getContentType());
}
示例8: MarshallingSource
import org.springframework.oxm.Marshaller; //导入依赖的package包/类
/**
* Create a new {@code MarshallingSource} with the given marshaller and content.
* @param marshaller the marshaller to use
* @param content the object to be marshalled
*/
public MarshallingSource(Marshaller marshaller, Object content) {
super(new MarshallingXMLReader(marshaller, content), new InputSource());
Assert.notNull(marshaller, "'marshaller' must not be null");
Assert.notNull(content, "'content' must not be null");
this.marshaller = marshaller;
this.content = content;
}
示例9: MarshallingMessageConverter
import org.springframework.oxm.Marshaller; //导入依赖的package包/类
/**
* Construct a new {@code MarshallingMessageConverter} with the given {@link Marshaller} set.
* <p>If the given {@link Marshaller} also implements the {@link Unmarshaller} interface,
* it is used for both marshalling and unmarshalling. Otherwise, an exception is thrown.
* <p>Note that all {@link Marshaller} implementations in Spring also implement the
* {@link Unmarshaller} interface, so that you can safely use this constructor.
* @param marshaller object used as marshaller and unmarshaller
* @throws IllegalArgumentException when {@code marshaller} does not implement the
* {@link Unmarshaller} interface as well
*/
public MarshallingMessageConverter(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 explicitly by using the " +
"MarshallingMessageConverter(Marshaller, Unmarshaller) constructor.");
}
else {
this.marshaller = marshaller;
this.unmarshaller = (Unmarshaller) marshaller;
}
}
示例10: setUp
import org.springframework.oxm.Marshaller; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
marshallerMock = mock(Marshaller.class);
unmarshallerMock = mock(Unmarshaller.class);
sessionMock = mock(Session.class);
converter = new MarshallingMessageConverter(marshallerMock, unmarshallerMock);
}
示例11: createMarshaller
import org.springframework.oxm.Marshaller; //导入依赖的package包/类
@Override
protected Marshaller createMarshaller() throws Exception {
JibxMarshaller marshaller = new JibxMarshaller();
marshaller.setTargetPackage("org.springframework.oxm.jibx");
marshaller.afterPropertiesSet();
return marshaller;
}
示例12: createMarshaller
import org.springframework.oxm.Marshaller; //导入依赖的package包/类
@Override
public Marshaller createMarshaller() throws Exception {
marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(CONTEXT_PATH);
marshaller.afterPropertiesSet();
return marshaller;
}
示例13: properties
import org.springframework.oxm.Marshaller; //导入依赖的package包/类
@Test
public void properties() throws Exception {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath(CONTEXT_PATH);
marshaller.setMarshallerProperties(
Collections.<String, Object>singletonMap(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT,
Boolean.TRUE));
marshaller.afterPropertiesSet();
}
示例14: createMarshaller
import org.springframework.oxm.Marshaller; //导入依赖的package包/类
@Override
protected Marshaller createMarshaller() throws Exception {
CastorMarshaller marshaller = new CastorMarshaller();
ClassPathResource mappingLocation = new ClassPathResource("mapping.xml", CastorMarshaller.class);
marshaller.setMappingLocation(mappingLocation);
marshaller.afterPropertiesSet();
return marshaller;
}
示例15: getMarshaller
import org.springframework.oxm.Marshaller; //导入依赖的package包/类
protected Marshaller getMarshaller() {
XmlBeansMarshaller marshaller = new XmlBeansMarshaller();
marshaller.setXmlOptions(new XmlOptions().setSaveSyntheticDocumentElement(new QName(metadata.getRequestElementNs(),
metadata.getRequestElementName(),
StandardXRoadConsumer.ROOT_NS)));
return marshaller;
}