Example usage for org.springframework.oxm.jaxb Jaxb2Marshaller setClassesToBeBound

List of usage examples for org.springframework.oxm.jaxb Jaxb2Marshaller setClassesToBeBound

Introduction

In this page you can find the example usage for org.springframework.oxm.jaxb Jaxb2Marshaller setClassesToBeBound.

Prototype

public void setClassesToBeBound(@Nullable Class<?>... classesToBeBound) 

Source Link

Document

Set the list of Java classes to be recognized by a newly created JAXBContext.

Usage

From source file:org.springframework.batch.item.xml.Jaxb2NamespaceMarshallingTests.java

protected Marshaller getMarshaller() throws Exception {

    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    marshaller.setClassesToBeBound(new Class<?>[] { QualifiedTrade.class });
    marshaller.afterPropertiesSet();/*from ww  w  .  java 2s  . c  om*/

    StringWriter string = new StringWriter();
    marshaller.marshal(new QualifiedTrade("FOO", 100, BigDecimal.valueOf(10.), "bar"),
            new StreamResult(string));
    String content = string.toString();
    assertTrue("Wrong content: " + content, content.contains("<customer>bar</customer>"));
    return marshaller;
}